Creates a blob of the required size
Device + Agent
Optional size of the new blob in bytes
This function creates a new blob. If the optional parameter is passed, the blob will be allocated that much memory and sized to that specified number of bytes, otherwise a zero-size blob is created. If you specify one or more bytes as the size, each byte in the resulting blob is automatically zero’d for you.
When you create a blob, it contains only the specified number of bytes. If you simply use, for instance,
local aBlob = blob();
then your blob’s size is initially zero and will stay so until you write data to it. Blobs are mutable and can increase or decrease in size. If they grow beyond their currently memory allocation, Squirrel will re-allocate the blob to an area of contiguous memory with room for the expanded blob, if sufficient free memory is available.
The method len() will show the blob’s current size: the amount of data it contains, which is the initial size plus any data beyond that that has since been written to it.
The resize() method sets the blob’s memory allocation, not its size. If the new allocation is smaller than the current one, size and allocation will inevitably coincide. But this is not the case if the new allocation is larger: Squirrel simply grants the blob enough contiguous memory space to grow into. It does not fill that extra space, so the blob’s size remains unchanged.