> My question is: Can i allocate and manage a shared memory without going through a struct?
If you were thinking of doing the shmat version of this,
1 2
|
int **arr = new int*[10];
for ( int i = 0 ; i < 10 ; i++ ) arr[i] = new int[100];
|
then the answer is no (or it's a world of pain).
The real problem comes in when your peer process calls shmat to get a pointer to arr, only to find out that it's been mapped to a different virtual address. This instantly renders all the arr[i] pointers in the second process as illegal addresses (they're only valid in the first process).
Picking your own shmaddr to pass to shmat would solve the problem, only to be replaced with how to choose a good shmaddr in the first place. If that fails, you're still SoL.
If you need variable sized 2D arrays, the simplest is to just allocate the single monolithic block of memory, then do your own
row*cols+col manual subscripting on it.