B
boltar2003
This is probably a question thats come up before but google doesn't seem to
be my friend on this one.
Is there some hack whereby a 2D array can be mapped onto a dynamically
allocated block of contiguous memory in C? Its easily done with 1D arrays
but if you use a double pointer for the 2D the memory can't be contiguous
as you have to allocate each single point in turn.
What I'd like to do is something like:
struct mystruct **array;
array = (struct mystruct **)<some preallocated shared memory>
:
:
array[1][2].val = 123;
Now I know this will crash as soon as it tries to dereference the 1st
level of the array but is there some clever way to do it?
Thanks for any help.
B2003
be my friend on this one.
Is there some hack whereby a 2D array can be mapped onto a dynamically
allocated block of contiguous memory in C? Its easily done with 1D arrays
but if you use a double pointer for the 2D the memory can't be contiguous
as you have to allocate each single point in turn.
What I'd like to do is something like:
struct mystruct **array;
array = (struct mystruct **)<some preallocated shared memory>
:
:
array[1][2].val = 123;
Now I know this will crash as soon as it tries to dereference the 1st
level of the array but is there some clever way to do it?
Thanks for any help.
B2003