[erlang-questions] mmap file to binary

Tony Rogvall <>
Sat Apr 10 00:04:38 CEST 2010

On 9 apr 2010, at 20.53, Mikael Pettersson wrote:

> Sverker Eriksson writes:
>> Tony Rogvall wrote:
>>>>> 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? ;-)
>> No, orig_bytes is still an array, but I don't think you need to change 
>> that. You could instead use the pointer 'bytes' in ProcBin to point to 
>> your mmap'ed data.
>> typedef struct proc_bin {
>>    Eterm thing_word;        /* Subtag REFC_BINARY_SUBTAG. */
>>    Uint size;            /* Binary size in bytes. */
>>    struct proc_bin *next;    /* Pointer to next ProcBin. */
>>    Binary *val;        /* Pointer to Binary structure. */
>>    byte *bytes;        /* Pointer to the actual data bytes. */
>>    Uint flags;            /* Flag word. */
>> } ProcBin;
> ... which is exactly what I wrote some number of messages ago.

Sorry I missed that.
You are right, I just found one spot in the gc where there may be a potential problem. But apart from that
the bytes pointer is untouched. I was also looking for the ERL_ONHEAP_BIN_LIMIT to see if the 
ProcBin was copied to heap somewhere, but all clear ;-)

A user_data field to pass to the creation of the magic binary could work I guess, then you could store
any kind of extra information like mmap'ed size etc. The user_data is then passed to the destructor.
The 'Binary' in this case is just a reference counting object?


More information about the erlang-questions mailing list