Using malloc directly...

BlitzMax Forums/BlitzMax Programming/Using malloc directly...

Arowx(Posted 2010) [#1]
Is there a simple way to call the c version of malloc directly?

I'm just playing with test apps to see if I can generate this memory access exception and was wondering if calling malloc directly as opposed to using MemAlloc would effect the results, in effect is the heap limit I'm hitting related to BlitzMax or the GCC compiler?


Zeke(Posted 2010) [#2]
local buffer:byte ptr=MemAlloc(1024)


sorry..
to use direct c commands use this:
SuperStrict

Extern "C"
	Function malloc:Byte Ptr(size:Int)
	Function free(buffer:Byte Ptr)
	Function memset:Byte Ptr(dest:Byte Ptr,value:Int,size:Int)
End Extern

Local buffer:Byte Ptr = malloc(1024)

memset(buffer , 123 , 1024)

For Local i:Int = 0 Until 1024
	Print buffer[i]
next

free(buffer)



grable(Posted 2010) [#3]
MemAlloc calls malloc yes, but it also aligns on 16 byte boundaries.
Potentially making the pointer incompatible with free and realloc.


Arowx(Posted 2010) [#4]
That does call malloc(), but only after wrapping it aligning it and adding about 16 bytes to it (for the GC system), so it's not direct!


Zeke(Posted 2010) [#5]
^^ edited my post to use direct c commands


Arowx(Posted 2010) [#6]
Cheers just what I needed!