[Mono-devel-list] malloc and free on CLI
Jeyasankar Kottalam
mono at jey.kottalam.net
Sat Jul 16 15:36:15 EDT 2005
Hello,
I'm the student writing GCC-CIL for Mono as part of Google's Summer of Code.
How should I implement malloc and free on CLI? I've come up with a couple of
ideas, but none of them seem particularly good to me:
- P/Invoke to native malloc and free
Problem: The binary becomes tied to the details of the underlying platform to
pull in a malloc from the appropriate library. Binary portability is lost.
- Writing a custom "allocator" in C# etc. This would be great if it's possible
to get a block of raw memory and tell the garbage collector not to move it.
Then it would be a simple matter of deleting the reference to the block when
free() is called, and the garbage collector would pick it up whenever.
Problem: I don't think we can get a chunk of raw memory from the runtime.
Seems like the best we could do is "new byte[foo]" which gives an _array
object_. Also I don't know of any mechanism to keep the block from being
shuffled around in memory by the garbage collector.
- The mysterious "localloc" instruction.
Problem: I think it is completly unrelated to malloc(), so never mind.
Any advice would be greatly appreciated. Sorry if I'm using the wrong
terminology, I'm new to both CIL and C#.
Thanks,
-Jey Kottalam
More information about the Mono-devel-list
mailing list