Thx Charles: I ended up casting to long in C via a plugin.
I test for nil ptrs using: if kUseMallocForImagedataMemblocks then return IsNull(m) else return (m=nil) end if depending on whether NewMemoryBlock or malloc was used for the allocation. P. On 5/24/06, Charles Yeomans <[EMAIL PROTECTED]> wrote:
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>
-- ------------------------------------------------------------------------------- Peter K. Stys, MD Professor of Medicine(Neurology), Senior Scientist Ottawa Health Research Institute, Div. of Neuroscience Ottawa Hospital / University of Ottawa Ontario, CANADA tel: (613)761-5444 fax: (613)761-5330 http://www.ohri.ca/profiles/stys.asp ------------------------------------------------------------------------------- _______________________________________________ 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>
