[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: memory debugging and C++ (program keeps crashing)



On Sun, Sep 29, 2002 at 02:54:19PM +0200, Russell Coker wrote:
> Also if you allocate memory that some C code will free or if you want to free 
> code that was (or might have been) allocated by C code then you need to use 
> malloc/free in your C++ program.

Russell is correct here. Since my code to interface with ORBit is
entirely C code, and uses the C bindings to ORBit, I need to use C
memory allocation functions. I have heard mixing functions[1] is not
guaranteed to work. (although now I think about it; I hope I am not
mixing C allocation functions with glib allocation functions, or is that
ok?).

I once tried using the C++ bindings for ORBit instead, but I run
into so many problems that a gave up and went to the C bindings
instead[2]. Also there seems to be little point in using the C++
bindings, because this library acts as an abstract C++ layer
which will support any communication protocol, not just ORBit.

Getting back to the initial topic, I think the memory leak programs that
detected no leaks were wrong, there is memory allocated in my program
with both new and malloc that is never freed...

Notes:
[1] that is malloc followed by delete or new followed by free on
the same memory block.

[2] Also I was really surprised with the response I got when I mailed
the ORBit C++ mailing list for help; it was along the lines of "I am not
a C++ expert so I can't help you...". At this point I decided to
switch to C for the C language interface instead.
-- 
Brian May <bam@debian.org>



Reply to: