Resources | Resources |



Local storage

The ILocalStorage interface provides a simple key/value storage facility. The keys are 32-bit numbers, and the values are opaque memory blocks.

Each stored memory block contains an LSEntry record, whose contents are used by the storage implementation. The intent is that the storage implementation can avoid allocation and freeing on Add & Remove by using the members of LSEntry to maintain its data structure.

Users provide only a pointer to the LSEntry when adding a record, and are given only the pointer to the LSEntry when they retrieve the record. Users are responsible for computing the memory block pointer from the LSEntry pointer.

A simple use model is to place the LSEntry at the beginning of the memory buffer by declaring it as the first member of a structure. This simplifies recovery of the data block pointer, reducing it to a simple cast. For example:

struct my_ls_data_type{
   LSEntry lse;
   ... ;  // other members of data buffer.

Users of the ILocalStorage object must identify the appropriate key that prevents collision with other users of the object. Unless the storage class specifies otherwise, the recommended approach for assigning keys is to use an address from the module image (such as the address of a function or a const char array). An address that is local to the client's code will prevent collision with others. Collision is not considered an error but only the last added record is returned by a call to get. If the last added record is removed then the second to last is returned by a call to get, and so forth.

static int save_to_ls(struct my_ls_data_type *pdata)
   nErr = ILocalStorage_Add(piLocalStorage, (uint32)save_to_ls, 
Required Files
Class ID(s)
Interface ID
platform\system\inc in the Brew MP SDK