On May 24, 2006, at 5:15 PM, Peter K. Stys wrote:
This is probably simple, but I need to get the address of a malloc'd
memblock:
dim m as MemoryBlock
Declare Function malloc lib "/usr/lib/libc.dylib" ( size as
Integer ) as
Ptr
m = malloc(1000)
n = integer(m) <= error
In C one would just coerce m to an integer, but RB complains.
I need this because the crash log reports a bad address access as a
0x...
hex number and I want to see if m is the culprit by looking where
it lives
in memory in relation to the offending address reported by the
crash log.
Has anyone had problems with malloc'd memblocks in RB? I have a very
obscure intermittent bug that I fear has nothing to do with my own
code.
I've used them quite a bit with no problems. In fact, I've got a
libc chapter semi-finished to add to my declares book. Let me
suggest that you change the library to "System.framework"; that way
you can switch to a soft declaration if you want, and it's a little
more portable. System.framework ultimately uses /usr/lib/libc.dylib.
Recent versions of REALbasic should return nil if malloc fails, I
think. But to check yourself, do the following.
Declare Function malloc lib "/usr/lib/libc.dylib" ( size as Integer )
as Integer
dim m as new MemoryBlock(4)
m.Long(0) = malloc(1000)
If m.Long(0) = 0 then
//something went wrong
End if
m = m.Ptr(0)
Charles Yeomans
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>