I did a little more poking around.
Buffer memory is allocated by the C function zalloc() – meaning that Buffers are not subject to s.options.memSize
.
In theory, it could use as much memory as you have in your system up to 2GB because internally it’s capped to a long int. In practice – https://www.quora.com/Why-does-malloc-fail –
It means that malloc (a C function that allocates memory) has failed - ie returned NULL. That could occur for a number of reasons:
- Your process has reached the limit of the amount of memory it is allowed to allocate
- Your system is unable to allocate any more memory - even though in theory your process has not exceeded it’s allocation.
- The internal stuctures that malloc uses to allocate and free memory has been corrupted, due to a buffer overflow or similar.
- There is sufficient free memory available to be allocated, but it is fragmented such that the requested memory cannot be allocated in a single chunk.
There might be other reasons too - but I have seen all of those in my career.
Of those, #3 is extremely unlikely. #4 is possible, but also unlikely unless you have a very small amount of memory and not much swap space (e.g. embedded device). #2 … doesn’t explain much? Like, maybe reboot? #1 may be interesting – is there some configuration active in your system that limits a process’s memory use? (E.g. “ulimit” in Linux.)
What system are you running? How much RAM does that machine have?
Going back to something concrete: I can reproduce the error message by providing a negative buffer size. That was actually my first theory – if calcPVRecSize
were returning such a large number that it became a negative 32-bit integer, then it would fail.
b = Buffer.alloc(s, 2 ** 35, 1);
-> Buffer(0, 34359738368.0, 1, 48000.0, nil)
/b_alloc: memory allocation failed
But 36828003.0 is nowhere near big enough for that. … ??? 26 bits, well below 31. (EDIT: Memory allocation in bytes would be this * 4 – but that’s still within the range of positive 32-bit integers.)
Last-ditch on that: Can you do this, to confirm the message that the server is receiving?
s.dumpOSC(1);
~fftsize = 8192; ~hop = 0.25; ~win = 0; f = Buffer.alloc(s, b.duration.calcPVRecSize(~fftsize, ~hop));
hjh