Is this safe

1. Can i safely reuse my pointer like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
DWORD len = SomeFunc();
if(len <=0)
    return;
wchar_t* buffer = new buffer[len];
...manipulate here
delete [] buffer;

len = OtherFunc();
if(len <=0)
    return;
buffer = new buffer[len];
...manipulate here
delete [] buffer;

...and so on

2. What happens if len == 1 and then i call
 
delete [] buffer;
1. If you are sure that you won't loose track of dynamically allocated memory, you can use a pointer however you wish.
ie: before reassigning a pointer make sure that you deleted it.

2. nothing special, you allocated an array of one element and you'll delete an array of one element
Thanks. It will be used in (scope of) some small function so i'll delete it before each new
allocation.
Topic archived. No new replies allowed.