> -----Original Message-----
> From: Christian Wallukat [mailto:Chr...@vo...]
> Sent: Friday, July 25, 2003 5:54 PM
> To: Abhijit Shylanath
> Subject: AW: [Dev-C++] Deleting an array
>
>
> Hi Abhijit,
>
>
> How can I do that ?
>
> In fact I need an array of something, where I can write Data into it.
>
> My idea is to use the array of PVOID[] in case of accessing over the
> PVOID[nNum],
> Allocate memory realloc(PVOID[nNum], nSize);
>
> Any idea how i can do it ?
>
>
> Kind regards
>
> Christian
Actually, the code that you're using should be alright for your purposes,
except for this:
When you delete[] pDataArray, you're actually delete'ing the array declared
like this:
PVOID pDataArray[1000];
NOT the array you allocated like this:
realloc(pDataArray[n], len);
That's why the error: you're trying to delete[] pDataArray, which was never
really new'ed.
To free pDataArray[n], use free(pDataArray[n]) (simple, isn't it? :-). Note
that data allocated with new should be delete'd, data allocated with
malloc() and its counterparts should be free()'d. They may allocate from
separate heaps, so you should not mix them.
So, to fix your above problem, you simply do
free(pDataArray[n]);
instead of
delete[] pDataArray.
Another thing, which I don't know if you're doing already is to NULL out all
the members of pDataArray at init-time. This is because of the working of
realloc(). If it gets a NULL pointer as its argument, it works like
malloc(). And the first time you allocate, it SHOULD work like malloc.
HTH.
PS: When you intend to post to the list, you have to `Reply All', not
`Reply'; otherwise only the sender will receive your reply, not the list.
This is a quirk of the mail-server used.
--
Abhijit Shylanath
Homepage: http://mudeth.tripod.com/
|