Open Inventor Release 2024.2.0
 
Loading...
Searching...
No Matches
SoMemoryObject.h
1/*=======================================================================
2 *** THE CONTENT OF THIS WORK IS PROPRIETARY TO FEI S.A.S, (FEI S.A.S.), ***
3 *** AND IS DISTRIBUTED UNDER A LICENSE AGREEMENT. ***
4 *** ***
5 *** REPRODUCTION, DISCLOSURE, OR USE, IN WHOLE OR IN PART, OTHER THAN AS ***
6 *** SPECIFIED IN THE LICENSE ARE NOT TO BE UNDERTAKEN EXCEPT WITH PRIOR ***
7 *** WRITTEN AUTHORIZATION OF FEI S.A.S. ***
8 *** ***
9 *** RESTRICTED RIGHTS LEGEND ***
10 *** USE, DUPLICATION, OR DISCLOSURE BY THE GOVERNMENT OF THE CONTENT OF THIS ***
11 *** WORK OR RELATED DOCUMENTATION IS SUBJECT TO RESTRICTIONS AS SET FORTH IN ***
12 *** SUBPARAGRAPH (C)(1) OF THE COMMERCIAL COMPUTER SOFTWARE RESTRICTED RIGHT ***
13 *** CLAUSE AT FAR 52.227-19 OR SUBPARAGRAPH (C)(1)(II) OF THE RIGHTS IN ***
14 *** TECHNICAL DATA AND COMPUTER SOFTWARE CLAUSE AT DFARS 52.227-7013. ***
15 *** ***
16 *** COPYRIGHT (C) 1996-2014 BY FEI S.A.S, ***
17 *** BORDEAUX, FRANCE ***
18 *** ALL RIGHTS RESERVED ***
19**=======================================================================*/
20/*=======================================================================
21** Author : David BEILLOIN (Mar 2007)
22**=======================================================================*/
23
24
25#ifndef SO_MEMORY_OBJECT_H
26#define SO_MEMORY_OBJECT_H
27
28#include <Inventor/misc/SoRefCounter.h>
29#include <Inventor/STL/map>
30#include <Inventor/SbDataType.h>
31#include <Inventor/threads/SbThreadMutex.h>
32
33#ifdef _WIN32
34#pragma warning(push)
35#pragma warning(disable:4251)
36#endif
37
38class SoBufferObject;
39
41//
42// Class: SoMemoryObject
43//
44// Class used to encapsulate a memory buffer pointer potentially shared
45// by multiple objects.
46// A reference counter is associated with this object to avoid deletion
47// until reference exists.
48//
50
70{
71public:
72
99
106
115 SoMemoryObject(void* buf, size_t byteSize, bool owner=true);
116
120 SoMemoryObject(void* buf, size_t byteSize, SbDataType type, CopyPolicy policy);
121
122
129
135
140 void* get() const;
141
145 size_t length() const;
146
150 inline SbDataType getType() const;
151
152private:
153
154 void setOwner(bool f) { m_policy = f ? NO_COPY_AND_FREE:NO_COPY; }
155
156 // setup a user allocated buffer
157 void setBuffer(void *buf, size_t byteSize);
158
159 // just change the m_size value without reallocation
160 void forceSize(size_t byteSize);
161
162 static SoMemoryObject* getMemoryObject(uint32_t id);
163 uint32_t getId() { return m_index; }
164 void setId( uint32_t id );
165
166 inline SoBufferObject* getBufferObject() const;
167
168private:
169 void registerMemObj();
170
174 void releaseValues();
175
179 template <typename T> void deleteValues(void *buffer);
180
184 template <typename T> void allocValues(void*& buffer, size_t byteSize);
185
186
187 bool m_userPointer;
188 SoBufferObject * m_bufferObj;
189
190 uint32_t m_index;
191 static uint32_t index;
192
193 typedef std::map< uint32_t, SoMemoryObject*> SoMemObjMap;
194 typedef SoMemObjMap::value_type SoMemObjValue;
195 static SoMemObjMap s_memObjMap;
196 static SbThreadMutex s_accessMutex;
197
198 SbDataType m_type;
199 CopyPolicy m_policy;
200};
201
202/*******************************************************************************/
205{
206 return m_type;
207}
208
210SoMemoryObject::getBufferObject() const
211{
212 return m_bufferObj;
213}
214
215#ifdef _WIN32
216#pragma warning(pop)
217#endif
218
219#endif // SO_MEMORY_OBJECT_H
220
221
Class encoding a data type.
Definition SbDataType.h:58
@ UNSIGNED_BYTE
unsigned byte
Definition SbDataType.h:66
<a href="IconLegend.html"><img src="extTGS.gif" alt="VSG extension" border="0"></a> Portable mutex c...
<a href="IconLegend.html"><img src="extTGS.gif" alt="VSG extension" border="0"></a> Abstract base cl...
<a href="IconLegend.html"><img src="extTGS.gif" alt="VSG extension" border="0"></a> Handle memory bu...
SoMemoryObject()
Default Constructor.
CopyPolicy
SoMemoryObject may be manipulating large amounts of memory.
@ NO_COPY_AND_FREE
Passed buffer used, SoMemoryObject will free.
@ NO_COPY
Passed buffer used, user will delete.
@ NO_COPY_AND_DELETE
Passed buffer used, SoMemoryObject will delete.
@ COPY
Open Inventor will make a copy of the data.
SbDataType getType() const
Returns the type of the encapsulated buffer.
virtual ~SoMemoryObject()
Destructor.
SoMemoryObject(SoBufferObject *bufObj, SbDataType type=SbDataType::UNSIGNED_BYTE, bool owner=true)
Constructor.
void * get() const
Returns a pointer to the encapsulated buffer.
SoMemoryObject(void *buf, size_t byteSize, bool owner=true)
Constructor.
size_t length() const
Returns the size in bytes of the encapsulated buffer.
SoMemoryObject(void *buf, size_t byteSize, SbDataType type, CopyPolicy policy)
Constructor.
Base class for ref-counted objects.