|
In an overloaded "<<" routine, I created an array on the heap. Then I used it to do what I needed, and just prior to the "return" statement, I deleted the same array. However, doing so causes the program to crash when I run it.
Interestingly, if I were to remove the "delete[]" statement, the program runs fine; it doesn't crash, but put it back in, and the program crashes.
The whole idea of using the "delete[]" statement on an array created on the heap, is to avoid memory leak. Here, it makes the program crash.
Does anybody have any idea why? Thanks!
William
Fortes in fide et opere!
|
|
|
|
|
I've had this before. Something is going wrong with your allocation. Let me guess, if you remove the [] from the delete statement, it won't crash. This isn't a real solution though, since if you're creating an array you need to delete[] the array.
Make sure that your array allocation is done correctly (it's allocating an array, not a scalar) and that you're not de-allocating the memory elsewhere.
|
|
|
|
|
You also can try to redefine operator delete in your class.
It dificult say more withiout source code.
p.s as you know operator delete described as follow:
void operator delete( void * );
void operator delete( void *, size_t );
Vitali
|
|
|
|
|
Thanks for your reply.
I believe I found the reason for the problem. It has to do with deleting that portion of memory that the "return" statement is outputting, which means if I were to deallocate the memory the array is using, the "return" statement would not work correctly (and is the reason for the crash).
A simpler soultion would be to create an array on the stack and let the routine deletes it when it exits the function.
William
Fortes in fide et opere!
|
|
|
|
|
WREY wrote:
A simpler soultion would be to create an array on the stack and let the routine deletes it when it exits the function.
I don't know your problem context but, if it really needs to be dynamic, how about using an STL vector?
The delete [] can be a bit of a bugger. A few months ago I had to maintain some code that was missing one of these and thus leaking memory. But when I put it in it crashed. However, the code was so complex that I never got to the bottom of it, and it (the memory leak) was low priority compared to everything else I had to do.
Kevin
|
|
|
|
|
This is typically caused by a previous error that went undetected. Possible errors are:
- deleting one memory location twice
- deleting an "invalid" pointer
- writing outside the boundaries of allocated memory
was the memory allocated with new[] or with new ?
"Der Geist des Kriegers ist erwacht / Ich hab die Macht" StS
sighist | Agile Programming | doxygen
|
|
|
|
|
This happens if you corrupt the heap, use the wrong pointer or delete the object more than once. I think if you write anything at ptr[-1] you will corrupt the lenght of the allocation and cause a crash...
John
|
|
|
|
|
Hi,
DOes anyone know how to capture the screen output, and write that to the disk (as AVI,or something else). I need to build an application wich records all the user interactions, it must also be hidden. It has to work like HyperCam (commercial program for this purpose).
It must work under win2000 (other systems are also OK).
Can anyone help me?
|
|
|
|
|
Hi,
Look at the
http://www.techsmith.com/download/devtoolsdefault.asp
Probably they will pay me for advertising LOL
Vitali
|
|
|
|
|
Hi,
Thanks Talik, for helping me.;)
But don't you know a version of this(or similar) software which is opensource?
|
|
|
|
|
is there a simple way to do this or am i gonna hafta write my own function?
|
|
|
|
|
Hi,
Try look at the MSDN "is, isw Routines"
This is very simle way.
Vitali
|
|
|
|
|
it would seem that those are for single characters im looking for something that tests an entire CString :P
|
|
|
|
|
also is there an easy way to convert a CString into an int?
|
|
|
|
|
CString str(5);
int n = _ttoi(str);
|
|
|
|
|
In this case read MSDN "Data Conversion Routines" such as atof, atoi, atol...
Vitali
|
|
|
|
|
Well, loop through for every character then. There's no single-function to do it
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
Actually there is!
CString::FindOneOf("AllTheCharactersThatAreNotNumbers...");
It's not the best way to do it, but it is possible
A student knows little about a lot.
A professor knows a lot about little.
I know everything about nothing.
|
|
|
|
|
|
I didn't even thought about UNICODE .
There are 2 proper ways you can solve this problem:
1) Write your own function
2) Just convert the string using atoi (or some other function) and check the return value
If time wouldn't be a problem I would write my own function...
A student knows little about a lot.
A professor knows a lot about little.
I know everything about nothing.
|
|
|
|
|
Hi,
I'm writing a tile-based arcade game for Win2000, no Directx, 24-bit screen depth and since I do some paralax scrolling requiring a lot of transparent blits, I have performance problems. As I think 256 colours would be enough for my application, I'd like to know if it is a good idea to create only 8-bit back buffer in memory and then blit it into 24-bit windows screen. Or, maybe have 24-bit back buffer and blit in 8-bit images. Would this speed-up my program?
Koxin
|
|
|
|
|
You may find this useful function in my CSkinProgress component at : http://www.codeproject.com/miscctrl/CSkinProgress.asp
Output bitmap : a bitmap created but NOT initalized
Input bitmap : your 8-bits bitmap
CDC : None to convert in the current DC, or a 24-bits compatible DC
The best is to include the CSkinProgress in your project (you might use it for various purposes ), then create a CSkinProgress object and use its CSkinProgress::ConvBitmap(...) function for your own purposes !
Kochise
In Cod we trust !
|
|
|
|
|
How do I convert a binary file to text file..?
Is there any API or any method by which I can achieve this...
Pratz
|
|
|
|
|
Hi,
some questions:
Is it realy a binary file? (you can't read anything if you view this file with e.g. Notepad). It is also possible, that you can read something with notepad, e.g. if you open a Worddocument as text file.
What type of binary file is it?
If it is realy a binary file, than you must know the coding rules (the same for decoding) for this type of file.
Regards
Frank
|
|
|
|
|
I'm not sure what you want to do, but anyway the difference between binary and text files is that text files are actually subgroup of binary files. That means that bytes (characters) in text files have only certain values specified in ASCII table (e.g. 'a' has a value of 97, 'b' 98, ...) while bytes in binary files can have any possible values (0-255).
Thus if you want to display a binary file in a text editor all you need to do is replace all non-ASCII characters with ASCII characters. Then the text editor will not find any character it can't deal with in the file and will consider it to be a text file.
Koxin
|
|
|
|