[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: avoiding copy - Luajit FFI
- From: Fabio Kaminski <fabiokaminski@...>
- Date: Tue, 7 Jun 2011 16:13:52 -0300
nice tip.. indeed it work.. thanks to point that out
> ffi.cdef [[
>> void * malloc(size_t size);
>> void free(void *);
>> ]]
> n = ffi.C.malloc(10)
> ncaddr = ffi.cast('uintptr_t', nc)
> =ncaddr
23003152ULL
> nc = ffi.cast('uint8_t *', n)
> ncaddr = ffi.cast('uintptr_t', nc)
> =ncaddr
23003152ULL
On Tue, Jun 7, 2011 at 3:28 PM, Duncan Cross <duncan.cross@gmail.com> wrote:
> On Tue, Jun 7, 2011 at 7:03 PM, Fabio Kaminski <fabiokaminski@gmail.com> wrote:
>> but cast from void * to char * give me a new address (pointing to
>> somewhere else) and not the same pointer:
>
> This is incorrect. What you are seeing here, when you print the
> pointer, is not the value of the pointer itself but of the FFI cdata
> object that has been allocated to house it.
>
> If you want to see the numeric value of a pointer, try
> tonumber(ffi.cast('intptr_t', ptr)).
>
> -Duncan
>
>