Re: REPOST: Memory-allocation rules with Delphi .exe, C/C++ .dll?

From: Catherine Rees Lay (spamtrap_at_polyhedron.org.uk)
Date: 07/30/04


Date: Fri, 30 Jul 2004 10:20:51 +0100

In article <b57fb7.0407291310.6b30568b@posting.google.com>, Elias
Sabbagh <ehs@sabbagh.com> writes
>Hi everyone--
>
>(reposting with what I hope is a clearer question...)
>
>Are either of these two scenarios forbidden?
>
>Scenario 1: Delphi .exe allocates mem (either SetLength() on dynamic
>array, or GetMem() on pointer). Passes it to routine found in a C/C++
>.dll (linked to using the cdecl calling convention). C/C++ .dll
>routine presumably stores pointer in a struct, occasionaly modifying
>values stored in the memory that the pointer points to. Later, Delphi
>.exe deallocates the mem (Finalize() or FreeMem()).
>
>Scenario 2: The opposite case -- C/C++ .dll provides specialty
>allocation routines, aglMalloc(), and aglFree(). Delphi .exe calls
>aglMalloc(), and keeps track of the Pointer that it returns. Delphi
>.exe modifies the memory through the use of a PSingle, an alias of
>Pointer. Later, Delphi calls aglFree() on the original Pointer.
>
>Thanks in advance,
>
>Elias Sabbagh

The only thing that would worry me is that the library bothered to
provide specialised allocation routines. Why? Is it possible that
something extra is being allocated and deallocated internally which
isn't visible to the caller? If so, scenario 1 will probably not work,
but scenario 2 should be OK.

Catherine.

-- 
Catherine Rees Lay
To email me, use my first name in front of the "at".


Relevant Pages

  • "Value properties" versus "Referenced properties"
    ... While Delphi is more of a "reference language" or "pointer language" where addresses of classes are stored in data pointers which are used via instructions. ... Properties in Delphi are more like a "value type", they/the properties also works on "values", the read/write values or records or even entire arrays. ...
    (alt.comp.lang.borland-delphi)
  • Re: How do I stop a TSP written in Delphi crashing on Add Provider?
    ... > You cast mod to a pointer to TCHAR but you declare it a char. ... >> Dim buffer As String ... >> I can successfully use the code above to access a functions in the Delphi ...
    (microsoft.public.win32.programmer.tapi)
  • Re: Multi Dimensional Array Reallocation ?
    ... As you can see the number of typecasts needed is pure horrifieing. ... >> But why can't delphi simply remember what type it was and do the ... Should the compiler treat that parameter as a TNextClass in ... > value you assigned to the pointer. ...
    (alt.comp.lang.borland-delphi)
  • Re: checking if pointer is NULL allowed?
    ... If it has been freed and causes the debug to crash, ... macro used in debugging routines that can take a pointer and return the ... There are routines that allocate a chunk of memory to store a number ...
    (comp.lang.c)
  • Re: checking if pointer is NULL allowed?
    ... If it has been freed and causes the debug to crash, ... generally not interested in the pointer once it has been freedCare to show how you would implement this? ... There are routines that allocate a chunk of memory to store a number ...
    (comp.lang.c)