LW Fog Info LW Item Info 2 Globals Table of Contents

"Global Memory"
"Global Render Memory"

Availability:  LightWave 6.0
Component:  Layout

These globals allow plug-ins to allocate and share named chunks of memory. The memory comes from a pool managed by Layout. Memory allocated through "Global Render Memory" is used during rendering and is freed automatically when rendering ends. "Global Memory" persists until the scene is cleared.

Global Call

   LWGlobalPool *memfunc;
   memfunc = global( "LW Global Memory", GFUSE_TRANSIENT );
   memfunc = global( "LW Global Render Memory", GFUSE_TRANSIENT );

The global function returns a pointer to an LWGlobalPool.

   typedef struct st_LWGlobalPool {
      LWMemChunk   (*first)  (void);
      LWMemChunk   (*next)   (LWMemChunk);
      const char * (*ID)     (LWMemChunk);
      int          (*size)   (LWMemChunk);
      LWMemChunk   (*find)   (const char *ID);
      LWMemChunk   (*create) (const char *ID, int size);
   } LWGlobalPool;
mem = first()
Returns the first memory chunk in the pool. This and the next function allow you to traverse the entire list of memory chunks in the pool. Use them if you need to search for memory chunks using criteria more complex than just the chunk ID string.

mem = next( mem )
Returns the next memory block in the list.

name = ID( mem )
Returns the chunk identifier. This is the name string that was passed to create.

bytes = size( mem )
Returns the size in bytes of a memory chunk.

mem = find( name )
Returns the memory chunk with the given ID. Multiple chunks may be created with the same ID, so this returns the first one.

mem = create( name, size )
Creates a memory chunk with the given size and ID and returns a pointer to the memory. If you want the name string to uniquely identify the chunk, you should try to find a chunk with your ID before using the ID in create.
 

Example

This code fragment allocates a render memory chunk named "my memory".

   #include <lwserver.h>
   #include <lwhost.h>
   #define COUNT 100

   static char name[] = "my widget memory";
   LWGlobalPool *memfunc;
   LWMemChunk mem;
   int *p, i;

   memfunc = global( "Global Render Memory", GFUSE_TRANSIENT );
   if ( !memfunc ) goto NoMemFunc;  /* global calls can fail */

   mem = memfunc->find( name );
   if ( !mem )
      mem = memfunc->create( name, COUNT * sizeof( int ));
   if ( !mem )
      goto ErrorNoMem;

   p = ( int * ) mem;
   for ( i = 0; i < COUNT; i++ ) {
      p[ i ] = ...