3
votes

I am calling a C DLL from a Delphi 2009 application and I keep getting errors when memory allocated by GetMem or AllocMem is passed to the DLL. The only way around I could avoid these errors was by using malloc from msvcrt.dll. What is malloc doing that the built-in memory routines aren't, and how can I get the built-in ones to work? I really don't like bypassing the built-in memory manager.

2
What sort of errors are you getting? There shouldn't be any problems unless the C dll tries to free or realloc the memory you passed to it, which it really shouldn't be doing. - Mason Wheeler
Agreed, but unfortunately "shouldn't be" and "isn't" are different things, and far too frequently so. - qid
Thank you for the answer. The dll has an option to take control of the memory and I was using it. I will rewrite my function to keep control of the memory. - user207886

2 Answers

4
votes

If the DLL ever attempts to free that memory or otherwise manipulate the memory allocation (e.g. expand/contract it), that would explain it. Mixing memory allocation systems is not recommended.

0
votes

Pay attention to Calling Convention, stdcall or cdecl .