Ecere SDK/eC Forums • View topic - Does the renew operator delete the previously allocated mem?




Ecere SDK/eC Forums

Ecere Developers Community

Does the renew operator delete the previously allocated mem?

General help with the eC language.

Does the renew operator delete the previously allocated mem?

Postby fedor_bel » Wed Mar 31, 2010 8:55 am

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.
fedor_bel
 
Posts: 21
Joined: Sun Mar 14, 2010 4:46 pm

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

Postby jerome » Wed Mar 31, 2010 8:57 am

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.
jerome
Site Admin
 
Posts: 622
Joined: Sat Jan 16, 2010 11:16 pm


Return to eC Language

Who is online

Users browsing this forum: No registered users and 3 guests

cron