Mail Archives: djgpp/1998/01/05/17:18:36
I don't know about the easiest, but this worked for me and if DJGPP doesn't give
an error, it works.
void **make_2d_array(size_t element_size, size_t left, size_t right)
{ // array[left][right] for clarity
void **ret;
int i;
// how do you 'new' a number like malloc()?
ret = malloc(4 * left); // array of far pointers
if (!ret)
return NULL;
for (i = 0; i < right; i++)
ret[i] = malloc(element_size * right);
for (i = 0; i < right; i++)
if (!ret[i])
return NULL;
return ret;
}
This worked for me, though it seems to be a large waste.
--
"DeHackEd"
Remove "nospam." from my email address to reply.
It's too late to run when you hear the boom.
Aleksi Kallio wrote in message <34ae5551 DOT 4918923 AT 195 DOT 10 DOT 154 DOT 8>...
>What's the easiest way to reserve memory for multidimensional array
>with "new"?
>
> |Mikko Aleksi Kallio |
> |akallio AT finlink DOT net |
> |www.finlink.net/~akallio/ |
- Raw text -