[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Re: Re: Serious (unreproducable) Problems
- From: "Nils Wogatzky" <nils@...>
- Date: Wed, 20 Oct 2004 05:07:44 +0200
I changed those calls into:
savObjects = new T*[Size];
and
delete [] savObjects;
right ?
And this time the App works quite fine,... again.
:-|
>
>Worse still: regardless of runtime library implementation new and delete typically call constructors and destructors respectively. This is something that - if I'm not mistaken - malloc and free simply won't do...
>
>So, regarding the sample code below: you could be in for a nasty surprise if you're not very careful about initializing the object array (allocated through malloc), depending on the destructors that are called later on (through the delete[]).
>
>Then again, Nils' problem could easily be caused by a multitude of other issues...
>
>I suggest to stay away from C++ (and several other programming languages, for that matter) if you're not really sure about what you're doing. If you're going to shoot yourself in the foot, you might as well find a more enjoyable way to do it.
>
>Ashwin.
>
>
>On Tue, 19 Oct 2004 19:02:26 -0700, Ben Sunshine-Hill <sneftel@gmail.com> wrote:
>
>> Bingo. new/delete and malloc/free do NOT play well together... they
>> aren't interchangeable in the slightest under most runtime libraries.
>>
>>
>> On Wed, 20 Oct 2004 03:59:55 +0200, Nils Wogatzky <nils@wogatzky.com> wrote:
>>> First of all thank you for your quick reply.
>>>
>>> Do I mix malloc with delete ?
>>>
>>> [Code]
>>> ...
>>> savObjects = (T**)malloc(Size * sizeof(Objects));
>>> ...
>>> delete [] savObjects;
>>> ...
>>> [/Code]
>>>
>>> like this ?
>>>
>>> Then I do, yes. I´m not that good in C++ =)
>>>
>>> To your second question ("..Use of objects..") I can reply: I just use function-calls.
>>>
>>> I´ll try to find a memory-debugging tool to fix the problem.
>>> (After that I´ll read some C++ - Tutorials and find out why I shouldn´t use malloc and delete;-) )
>>>
>>> Thank you
>>>
>--
>no signature is a signature.
>