[erlang-questions] mmap file to binary

Tony Rogvall <>
Fri Apr 9 15:21:42 CEST 2010


On 9 apr 2010, at 13.46, Max Lapshin wrote:

> On Fri, Apr 9, 2010 at 3:37 PM, Tony Rogvall <> wrote:
>> Check out the ErlNifResource stuff, this will handle the garage collection for data like this.
>> (yes, it is aso using the magic stuff)
> 
> No, it is not enough, because ErlNifResourceDtor receives only pointer
> to data, but mmap also requires size in bytes.
> So to implement mmap we need to use other function, not nif_resource_dtor
> 

I know that ErlNifResource is not enough but it's a step in the right direction.

What I am saying is that what you want is not really possible to implement in the
way the runtime system handles binaries today.
But that the amount of work to fix it is not that much.

>> My suggestions for drivers is one ErlDrvObject where you can store the actual object data
>> inline and pass it back and forth from driver to runtime. It will appear as a binary.
> 
> you think, that it may be easier to implement it as a driver?
> 
No. Not for mmap'ed data, since you do not need to poll any file descriptors.

>> 
>> Still the orig_bytes must be change. There are not to many places in the VM that uses the fact
>> that orig_bytes is not a pointer, so the change should not be hard (if it's not done already ;-)
>> 
> 
> I haven't understood: is the problem with orig_bytes now?


Well...  OTP team? ;-)

/Tony



More information about the erlang-questions mailing list