GC interaction with malloc/free

H. S. Teoh hsteoh at qfbox.info
Thu Jan 5 19:54:01 UTC 2023


On Thu, Jan 05, 2023 at 07:49:38PM +0000, DLearner via Digitalmars-d-learn wrote:
> Suppose there is a D main program (not marked anywhere with @nogc),
> that _both_
> 
> A: Calls one or more C functions that themselves call malloc/free; and
> also
> B: Calls one or more D functions that themselves call malloc/free via
> `import core.stdc.stdlib;`
> 
> Assuming the malloc/free's are used correctly, does this situation
> risk crashing the D main program?
[...]

core.stdc.stdlib.{malloc,free} *is* the exact same malloc/free that C
uses, it has nothing to do with the GC.  The allocated memory is taken
from the malloc/free part of the heap, which is disjoint from the heap
memory managed by the GC.

So, it should not cause any crashes.


T

-- 
Маленькие детки - маленькие бедки.


More information about the Digitalmars-d-learn mailing list