Skip to content

Commit

Permalink
Corrected alloc/2 that did not work in R13B.
Browse files Browse the repository at this point in the history
alloc/2 used to call the driver that would allocate a driver binary.
In R13B, however, a binary smaller than 65 bytes will be
automatically converted to a heap binary.

We work around the problem by always allocating a binary with
a size of at least 65 bytes. We do it directly in Erlang code
without calling the driver (there was never really any need
to use the driver just to allocate a new binary).
  • Loading branch information
bjorng committed May 5, 2009
1 parent 1ae6c9b commit 780862c
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/sdl_util.erl
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,15 @@
%% Erlang term; thus there is no need to worry about freeing
%% the memory.
alloc(Size0, Type) ->
Size = mem_size(Type, Size0),
Bin = call(?MYGL_malloc, <<Size:32/native>>),
%% Make sure that the size is at least 65 bytes
%% to guarantee that the binary will be allocated
%% outside of the heap.
Size = case mem_size(Type, Size0) of
Size1 when Size1 < 65 -> 65;
Size1 -> Size1
end,

Bin = <<0:Size/unit:8>>,
#sdlmem{type=Type,bin=Bin,size=Size0}.

%% Func: getBin
Expand Down

0 comments on commit 780862c

Please sign in to comment.