Open Inventor Release 2024.1.3
 
Loading...
Searching...
No Matches
SoMemoryObject Class Reference

VSG extension Handle memory buffer with reference counter. More...

#include <Inventor/misc/SoMemoryObject.h>

+ Inheritance diagram for SoMemoryObject:

Public Types

enum  CopyPolicy {
  COPY = 0 ,
  NO_COPY ,
  NO_COPY_AND_DELETE ,
  NO_COPY_AND_FREE
}
 SoMemoryObject may be manipulating large amounts of memory. More...
 

Public Member Functions

 SoMemoryObject ()
 Default Constructor.
 
 SoMemoryObject (void *buf, size_t byteSize, bool owner=true)
 Constructor.
 
 SoMemoryObject (void *buf, size_t byteSize, SbDataType type, CopyPolicy policy)
 Constructor.
 
 SoMemoryObject (SoBufferObject *bufObj, SbDataType type=SbDataType::UNSIGNED_BYTE, bool owner=true)
 Constructor.
 
virtual ~SoMemoryObject ()
 Destructor.
 
void * get () const
 Returns a pointer to the encapsulated buffer.
 
size_t length () const
 Returns the size in bytes of the encapsulated buffer.
 
SbDataType getType () const
 Returns the type of the encapsulated buffer.
 
- Public Member Functions inherited from SoRefCounter
void ref () const
 Adds a reference to an instance.
 
void unref () const
 Removes a reference from an instance.
 
void unrefNoDelete () const
 unrefNoDelete() should be called when it is desired to decrement the reference count, but not delete the instance if this brings the reference count to zero.
 
int getRefCount () const
 Returns current reference count.
 
void lock () const
 lock this instance.
 
void unlock () const
 unlock this instance.
 

Detailed Description

VSG extension Handle memory buffer with reference counter.

This object encapsulates a memory buffer with a reference counter, allowing it to be shared across multiple objects. The buffer will be released when no more references to it exist.

SEE ALSO

SoRefCounter, SoRef,

Definition at line 69 of file SoMemoryObject.h.

Member Enumeration Documentation

◆ CopyPolicy

SoMemoryObject may be manipulating large amounts of memory.

It is therefore convenient to be able to set the memory usage policy.

Enumerator
COPY 

Open Inventor will make a copy of the data.

NO_COPY 

Passed buffer used, user will delete.

NO_COPY_AND_DELETE 

Passed buffer used, SoMemoryObject will delete.

Use this if memory is allocated with operator "new[]".

NO_COPY_AND_FREE 

Passed buffer used, SoMemoryObject will free.

Use this if memory is allocated with "malloc".

Definition at line 78 of file SoMemoryObject.h.

Constructor & Destructor Documentation

◆ SoMemoryObject() [1/4]

SoMemoryObject::SoMemoryObject ( )

Default Constructor.

No memory area is handled, but default parameters are set to a type of SbDataType::UNSIGNED_BYTE and a CopyPolicy of NO_COPY_AND_DELETE

◆ SoMemoryObject() [2/4]

SoMemoryObject::SoMemoryObject ( void *  buf,
size_t  byteSize,
bool  owner = true 
)

Constructor.

Takes the object to manage.
Default type will be assigned to UNSIGNED_BYTE. if owner flag is true, Policy will be set to NO_COPY_AND_FREE , then the memory area pointed to by buf should be allocated by malloc/realloc C function in order to be correctly deleted during unref. else policy is NO_COPY (disables automatic release of the managed buffer).

◆ SoMemoryObject() [3/4]

SoMemoryObject::SoMemoryObject ( void *  buf,
size_t  byteSize,
SbDataType  type,
CopyPolicy  policy 
)

Constructor.

Takes the object to manage.

◆ SoMemoryObject() [4/4]

SoMemoryObject::SoMemoryObject ( SoBufferObject bufObj,
SbDataType  type = SbDataType::UNSIGNED_BYTE,
bool  owner = true 
)

Constructor.

Takes the buffer object to manage.
Policy is NO_COPY_AND_DELETE if owner flag is true, else policy is NO_COPY (disables automatic release of the buffer object).

◆ ~SoMemoryObject()

virtual SoMemoryObject::~SoMemoryObject ( )
virtual

Destructor.

It will be called when there are no more references to this object. It will destroy the managed buffer as well.

Member Function Documentation

◆ get()

void * SoMemoryObject::get ( ) const

Returns a pointer to the encapsulated buffer.

◆ getType()

SbDataType SoMemoryObject::getType ( ) const
inline

Returns the type of the encapsulated buffer.

Definition at line 204 of file SoMemoryObject.h.

◆ length()

size_t SoMemoryObject::length ( ) const

Returns the size in bytes of the encapsulated buffer.


The documentation for this class was generated from the following file: