Initialising a blob


I have some code I’m putting together to control a graphic LCD screen and I need to store a buffer for the contents of the screen as well as some artifacts such as font tables.

At the moment I’m using an array and want to change this to a blob to reduce the memory overhead, but wanted to know if there’s an efficient way to initialise a blob to some set value (e.g. a font table). Do I have to create the blob and then write in a byte at a time?



No, blobs are dynamic so this doesn’t work like that. Right now for fonts you should set them up as const strings, eg:

const table = “…”;

As I presume you’re storing binary in there, you could pre-process this and put it in using \xXX strings. These take no more space than blobs. The advantage of blobs vs strings are that you can read and write any index in them, and preallocate a size which helps reduce memory fragmentation.

Right now in release-7 these will be copied to RAM at runtime, taking away from your workspace, but release-9 will leave them in flash. Depending on how big your screen is you may have fun with available memory…