Re: C++ to Delphi conversion

From: Rudy Velthuis (TeamB) (rvelthuis_at_gmx.de)
Date: 12/23/03


Date: 23 Dec 2003 04:40:13 -0700

Oliver Young wrote:

>
> > If the (C++) DLL allocated the memory
> > with 'new', then you must pass the (variable, char*) memory back
> > to the DLL so that it can call 'delete'. Delphi has no
> > 'delete' operator so it will not be able to free the
> > memory correctly.
>
> Is this truth? Delphi can't free char* (PCHAR) output pointer from
> function?

The DLL and the calling code don't use the same memory manager, so no, it
can't. In general, it is never very wise to return a newly created buffer
as a function result, unless you also provide a function to deallocate
the buffer.

But I would let the caller do the memory handling, and only let the
function fill or read the buffer.

-- 
Rudy Velthuis (TeamB)
"The only thing necessary for the triumph of evil is for good men to do 
 nothing."
 -- Edmund Burke (1729-1797)


Relevant Pages

  • Re: Discovering variable types...
    ... >- but I suppose MS expect us to use wrappers ... memory allocations for your variables from disk as well. ... >They most certainly are of fixed size, changing the size of a String ... >>me to keep buffer size and current postion right in the memory block. ...
    (comp.lang.pascal.delphi.misc)
  • Re: Discovering variable types...
    ... >memory it points to is on the heap. ... sequentially reading data, if one is randomly reading records, then a ... >project is what's prompting me to improve disk access. ... from a memory buffer I can do it in about a second. ...
    (comp.lang.pascal.delphi.misc)
  • Re: Multicast Directshow Graph Bridging, COW Rustling, & the Use of Portable Holes in Cartoon Ph
    ... memory to share buffer pools across processes and works pretty well. ... You get two basic Direct Show filters, ... issue each GMF-source a virtual memory alias with COW ...
    (microsoft.public.win32.programmer.directx.video)
  • Re: PCI bus-master and large contiguous memory buffers
    ... I built my scatter gather list in SRAM that was on my device, ... could have done it in system memory had I needed to. ... interrupt when a buffer was filled, the application would save the buffer to ... beginning of the recording I made a device IO control call to my driver. ...
    (microsoft.public.development.device.drivers)
  • Re: PCI bus-master and large contiguous memory buffers
    ... As soon as device reaches the end of the buffer ... Sure, I am developing both PCI adapter and device driver, so, it is ... not afford reinitializing DMA on my device after every transfer. ... x86 CPU memory management structures I never tried to dig into Windows ...
    (microsoft.public.development.device.drivers)