With each class is associate a number of "buffers". This is where you are asked to store any data you may create that are related to the classes. For example, if you need to create a work copy of the image, you create a buffer for it and store it in that buffer.
There is a mechanism to insure that the buffer you create will not be confused with buffers from other DLLs. You assign an your own ID to the buffer. Since these are 32 bit values, hopefully yours will be unique.
One of the advantage of these buffers is that the memory used in the buffers will be under the supervision of the Memory Manager.
Here's how to create and use a "user" buffer.
Create the buffer
First, you create the buffer. Buffers are instances of the SliceO_Buffer class.
You must assign a priority to this buffer (from 0x01 to 0x0F). When the memory manager need to do a memory cleanup, it will remove memory starting with the higher priority values and going down until it has freed enough memory.
SliceO_Buffer *buf_local = new SliceO_Buffer( YOUR_PRIORITY ) ;
Assign name and memory to the buffer
Then assign a name to the buffer.
buf_local->Name_Set( "your_buffer" ) ;
and the desired memory to your buffer.
here you have 2 choices:
·A simple memory block
buf_local->Data_New( dim ) ;
·A 2D matrix
buf_local->Matrix_New( x, y, dim ) ;
Note: You can also have an array of memory buffers inside a memory buffer using the "m_child_nb" and "m_child_pt" variables. But when the memory manager does a cleanup, he only look at the priority of the first buffer before deciding to delete.
Assign buffer to "user" structure
And finally you assign this buffer to the "user" structure in your class using the "User_Set" method. The "ID" you provide must be unique.
Note:
class_pointer->User_Set( YOUR_ID, buf_local ) ;
Accessing the "user" buffers
You can retrieve a pointer to the buffer with the method "User_Get" (make sure you test the validity of the returned pointer since the memory manager may have deleted the buffer):
SliceO_Buffer *buf_local = class_pointer->User_Get( YOUR_ID ) ;
if ( ! buf_local )
...
Once you do have a pointer to the buffer, you can lock it to prevent having it destroyed while you are working with it:
buf_local->Lock() ;
You can get a pointer to the memory associated with the buffer:
·Simple memory block:
void *data = buf_local->Data_Get() ;
·2D matrix:
unsigned short matrix_x = buf_local->Matrix_Get_X() ;
unsigned short matrix_y = buf_local->Matrix_Get_Y() ;
unsigned short matrix_dim = buf_local->Matrix_Get_Dim() ;
void **matrix_data = buf_local->Matrix_Get() ;
Deleting the "user" buffers
When you do not need it anymore, you can delete your buffer (and free all associated memory) withthe "User_Delete" method:
class_pointer->User_Delete( YOUR_ID ) ;
The Memory Manager and the "User" buffers
The Memory Manager keep a watch on the available RAM memory. If you are running low on memory, the manager will start to delete memory buffers. For this it use the priority values that have been assigned to the buffers. It will delete the lowest priority buffers (those having the higher priority number) until enough memory has been recuperated. This is why when you use the "User_Get" method, you have to make sure the pointer you received is valid. If the buffer has been recycled, you will get a NULL pointer.
The buffer shortcuts
Some of the "SliceO_Frame" class buffers are used often enough to justify having a shortcut to them in the SliceO_Frame class. If the shortcut is not "NULL" you can use it, otherwise you have to use the "User_Get" method to get access to the buffer.
SliceO_Class elements
The variables and methods relating to the "User" buffers in the SliceO_Class class are: