Hi guys, I’m messing around a bit with replacing contents of Buffers on the fly, and in search of a way to change the numFrames of a Buffer I discovered that it actually works if I do this:
b = Buffer.alloc(s,512,1);
and then:
(
b.numFrames = 1024;
b.alloc;
)
The buffer is now 1024 frames. It appears to remove the old buffer and creates the new zero’d one on the server with the same bufnum and adjusted numFrames. It seems a bit sketchy though. My question is; is this safe to do? Does it actually remove the old buffer or will this cause a memory leak? In other words; is this a feature or a bug ;-)?
Memory leak. You’ll need to call free on the old buffer first.
@cian That’s not true! The buffer number is allocated either in the Buffer constructor or in the Buffer.allocclass method. Calling alloc on a Buffer instance only sends the /b_alloc message to the Server. This will replace any existing buffer at that index with a new buffer. There’s no memory leak.