Problem with overwriting pointer
ok, i have a problem with memory management in my program...and i'm not sure how to go about fixing it. From what i';ve picked up, declaring a pointer using new and an amount makes that memory dedicated to the pointer, however, if i write (say a string of 256 chars to a 256bit pointer) it doesn't overwrite, it spills into unclaimed memory. This won't cause immediate effects, but this program will be run constantly and the write will happen hundreds of thousands of times a day most likely. So that would be very very bad. I won't confuse you with the junk in my loop, but i'll convey the basic idea of what's wrong:
Code:
//////GLOBALS
char * szBuffer=new char[256];
int main()
{
while(bool something)
{
//windows read file operation here...reads 256 chars to szBuffer
//something makes the loop continue or end
}
delete szBuffer[];
szBuffer=NULL;
}
i first discovered the bug when the program closed, however i din't know what it meant (i now know what it does as i mentioned earlier)
i found a work around which i used so i could show my boss that i hadn't worked on nothing for the last 2 weeks in which i made the pointer null before deleting. Basically it just makes windows miss the error, lol. So, i'd like your guru opinions on what to do.
One thing i tried was deleting and nulling the pointer at the end of the loop each time then at the beginning of the loop if the pointer ! (didn't exist) then i'd recreate it with new...but that didn't work...so thanks for any help you can give me.