Does the renew operator delete the previously allocated mem?

General help with the eC language.
Post Reply
fedor_bel
Posts: 21
Joined: Sun Mar 14, 2010 4:46 pm

Does the renew operator delete the previously allocated mem?

Post by fedor_bel »

Hello,

Does the renew operator delete the previously allocated memory?

Like if some memory was allocated with new and then I call the renew operator and a completely new block of memory will be allocated, will the old block be freed?

Hopefully it will.
jerome
Site Admin
Posts: 608
Joined: Sat Jan 16, 2010 11:16 pm

Re: Does the renew operator delete the previously allocated mem?

Post by jerome »

Hi fedor.

Yes the renew allocator either reuses, or frees then allocates a new block of memory.
It works similarly to the C function 'realloc'.

Typical usage:

Code: Select all

byte * mem = new byte[10];
mem = renew mem byte[20];
Use with complete peace of mind. No memory leaks.

Also note the zeroing versions:

Code: Select all

byte * mem = new0 byte[10];
mem = renew0 mem byte[20];
Which will only zero out the new portion of renew'ed memory.
Post Reply