Use ON_Workspace classes on the stack to efficiently get and automatically clean up workspace memory and scratch files. More...
#include <opennurbs_workspace.h>
Public Member Functions | |
ON_Workspace () | |
ON_Workspace classes should be on the stack or as members on classes that are never copied. The destructor frees memory that was allocated by ON_Workspace::GetMemory and closes files that were opened with ON_Workspace::OpenFile. More... | |
~ON_Workspace () | |
The destructor frees memory that was allocated by ON_Workspace::GetMemory and closes files that were opened with ON_Workspace::OpenFile. More... | |
void | Destroy () |
The destructor frees memory that was allocated by ON_Workspace::GetMemory and closes files that were opened with ON_Workspace::OpenFile. The workspace can be used again after calling destroy. More... | |
double * | GetDoubleMemory (size_t count) |
Gets an array of doubles that will be freed by ~ON_Workspace. The intent of ON_Workspace::GetDoubleMemory is to provide an easy way to get scratch double arrays without having to worry about cleaning up before returning. More... | |
double ** | GetDoubleMemory (size_t row_count, size_t col_count) |
Gets an matrix of doubles More... | |
int * | GetIntMemory (size_t count) |
Gets an array of integers that will be freed by ~ON_Workspace. The intent of ON_Workspace::GetIntMemory is to provide an easy way to get scratch integer arrays without having to worry about cleaning up before returning. More... | |
int ** | GetIntMemory (size_t row_count, size_t col_count) |
Gets an matrix of integers More... | |
void * | GetMemory (size_t sz) |
Gets a block of heap memory that will be freed by ~ON_Workspace. The intent of ON_Workspace::GetMemory is to provide an easy way to get blocks of scratch memory without having to worry about cleaning up before returning. More... | |
ON_3dPoint * | GetPointMemory (size_t count) |
Gets an array of ON_3dPoints that will be freed by ~ON_Workspace. The intent of ON_Workspace::GetPointMemory is to provide an easy way to get scratch point arrays without having to worry about cleaning up before returning. More... | |
ON_3dVector * | GetVectorMemory (size_t count) |
Gets an array of ON_3dVectors that will be freed by ~ON_Workspace. The intent of ON_Workspace::GetVectorMemory is to provide an easy way to get scratch Vector arrays without having to worry about cleaning up before returning. More... | |
double * | GrowDoubleMemory (double *ptr, size_t count) |
Grows the array of doubles that was allocated by GetDoubleMemory or GrowDoubleMemory. More... | |
int * | GrowIntMemory (int *ptr, size_t count) |
Grows the array of integers that was allocated by GetIntMemory or GrowIntMemory. More... | |
void * | GrowMemory (void *ptr, size_t sz) |
Grows a block of heap memory that was allocated by ON_Workspace::GetMemory. More... | |
ON_3dPoint * | GrowPointMemory (ON_3dPoint *ptr, size_t count) |
Grows the array of points that was allocated by GetPointMemory or GrowPointMemory. More... | |
ON_3dVector * | GrowVectorMemory (ON_3dVector *ptr, size_t count) |
Grows the array of vectors that was allocated by GetVectorMemory or GrowVectorMemory. More... | |
void | KeepAllMemory () |
Calling KeepAllMemory() has the same effect as calling KeepMemory(p) for every active allocation in the workspace. After calling KeepAllMemory(), you can no longer use Grow...() on the pointers and you are responsible for using onfree() to release the memory when it is no longer needed. More... | |
bool | KeepFile (FILE *fileptr) |
If you want to prevent ~ON_Workspace from closing a file that was opened with ON_Workspace::OpenFile, then pass the returned FILE pointer to KeepFile. After calling KeepFile, the caller is responsible for calling ON::CloseFile to close the file. More... | |
bool | KeepMemory (void *ptr) |
Calling the KeepMemory() function with a pointer returned from one of the Get...() or Grow...() calls keeps the workspace destructor from freeing the memory. After calling KeepMemory(), you can no longer use Grow...() on the pointer. The caller is responsible for using onfree() to release the memory when it is no longer needed. More... | |
FILE * | OpenFile (const char *filename, const char *filemode) |
Uses ON::OpenFile to open a file. ~ON_Workspace will close the file. More... | |
FILE * | OpenFile (const wchar_t *filename, const wchar_t *filemode) |
Uses ON::OpenFile to open a file. ~ON_Workspace will close the file. More... | |
Use ON_Workspace classes on the stack to efficiently get and automatically clean up workspace memory and scratch files.
ON_Workspace::ON_Workspace | ( | ) |
ON_Workspace classes should be on the stack or as members on classes that are never copied. The destructor frees memory that was allocated by ON_Workspace::GetMemory and closes files that were opened with ON_Workspace::OpenFile.
ON_Workspace::~ON_Workspace | ( | ) |
The destructor frees memory that was allocated by ON_Workspace::GetMemory and closes files that were opened with ON_Workspace::OpenFile.
void ON_Workspace::Destroy | ( | ) |
The destructor frees memory that was allocated by ON_Workspace::GetMemory and closes files that were opened with ON_Workspace::OpenFile. The workspace can be used again after calling destroy.
double* ON_Workspace::GetDoubleMemory | ( | size_t | count | ) |
Gets an array of doubles that will be freed by ~ON_Workspace. The intent of ON_Workspace::GetDoubleMemory is to provide an easy way to get scratch double arrays without having to worry about cleaning up before returning.
count | [in] (>0) number of doubles in memory block. If count <= 0, then nullptr is returned. |
double** ON_Workspace::GetDoubleMemory | ( | size_t | row_count, |
size_t | col_count | ||
) |
Gets an matrix of doubles
row_count | [in] (>0) number of rows |
col_count | [in] (>0) number of columns |
int* ON_Workspace::GetIntMemory | ( | size_t | count | ) |
Gets an array of integers that will be freed by ~ON_Workspace. The intent of ON_Workspace::GetIntMemory is to provide an easy way to get scratch integer arrays without having to worry about cleaning up before returning.
count | [in] (>0) number of integers in memory block. If count <= 0, then nullptr is returned. |
int** ON_Workspace::GetIntMemory | ( | size_t | row_count, |
size_t | col_count | ||
) |
Gets an matrix of integers
row_count | [in] (>0) number of rows |
col_count | [in] (>0) number of columns |
void* ON_Workspace::GetMemory | ( | size_t | sz | ) |
Gets a block of heap memory that will be freed by ~ON_Workspace. The intent of ON_Workspace::GetMemory is to provide an easy way to get blocks of scratch memory without having to worry about cleaning up before returning.
sz | [in] (>0) size of memory block in bytes. If sz <= 0, then nullptr is returned. |
ON_3dPoint* ON_Workspace::GetPointMemory | ( | size_t | count | ) |
Gets an array of ON_3dPoints that will be freed by ~ON_Workspace. The intent of ON_Workspace::GetPointMemory is to provide an easy way to get scratch point arrays without having to worry about cleaning up before returning.
count | [in] (>0) number of points in memory block. If count <= 0, then nullptr is returned. |
ON_3dVector* ON_Workspace::GetVectorMemory | ( | size_t | count | ) |
Gets an array of ON_3dVectors that will be freed by ~ON_Workspace. The intent of ON_Workspace::GetVectorMemory is to provide an easy way to get scratch Vector arrays without having to worry about cleaning up before returning.
count | [in] (>0) number of Vectors in memory block. If count <= 0, then nullptr is returned. |
double* ON_Workspace::GrowDoubleMemory | ( | double * | ptr, |
size_t | count | ||
) |
Grows the array of doubles that was allocated by GetDoubleMemory or GrowDoubleMemory.
ptr | [in] pointer returned by an earlier call to GetDoubleMemory or GrowDoubleMemory. |
count | [in] (>0) number of doubles in memory block. If count <= 0, then nullptr is returned. If ptr was not allocated by this ON_Workspace class, then nullptr is returned. |
int* ON_Workspace::GrowIntMemory | ( | int * | ptr, |
size_t | count | ||
) |
Grows the array of integers that was allocated by GetIntMemory or GrowIntMemory.
ptr | [in] pointer returned by an earlier call to GetIntMemory or GrowIntMemory. |
count | [in] (>0) number of integers in memory block. If count <= 0, then nullptr is returned. If ptr was not allocated by this ON_Workspace class, then nullptr is returned. |
void* ON_Workspace::GrowMemory | ( | void * | ptr, |
size_t | sz | ||
) |
Grows a block of heap memory that was allocated by ON_Workspace::GetMemory.
ptr | [in] pointer returned by an earlier call to GetMemory or GrowMemory. |
sz | [in] (>0) size of memory block in bytes. If sz <= 0, then nullptr is returned. If ptr is not nullptr and was not allocated by an earlier call to GetMemory or GrowMemory, then nullptr is returned. |
ON_3dPoint* ON_Workspace::GrowPointMemory | ( | ON_3dPoint * | ptr, |
size_t | count | ||
) |
Grows the array of points that was allocated by GetPointMemory or GrowPointMemory.
ptr | [in] pointer returned by an earlier call to GetPointMemory or GrowPointMemory. |
count | [in] (>0) number of points in memory block. If count <= 0, then nullptr is returned. If ptr was not allocated by this ON_Workspace class, then nullptr is returned. |
ON_3dVector* ON_Workspace::GrowVectorMemory | ( | ON_3dVector * | ptr, |
size_t | count | ||
) |
Grows the array of vectors that was allocated by GetVectorMemory or GrowVectorMemory.
ptr | [in] pointer returned by an earlier call to GetVectorMemory or GrowVectorMemory. |
count | [in] (>0) number of vectors in memory block. If count <= 0, then nullptr is returned. If ptr was not allocated by this ON_Workspace class, then nullptr is returned. |
void ON_Workspace::KeepAllMemory | ( | ) |
Calling KeepAllMemory() has the same effect as calling KeepMemory(p) for every active allocation in the workspace. After calling KeepAllMemory(), you can no longer use Grow...() on the pointers and you are responsible for using onfree() to release the memory when it is no longer needed.
bool ON_Workspace::KeepFile | ( | FILE * | fileptr | ) |
If you want to prevent ~ON_Workspace from closing a file that was opened with ON_Workspace::OpenFile, then pass the returned FILE pointer to KeepFile. After calling KeepFile, the caller is responsible for calling ON::CloseFile to close the file.
fileptr | [in] pointer returned by OpenFile. |
bool ON_Workspace::KeepMemory | ( | void * | ptr | ) |
Calling the KeepMemory() function with a pointer returned from one of the Get...() or Grow...() calls keeps the workspace destructor from freeing the memory. After calling KeepMemory(), you can no longer use Grow...() on the pointer. The caller is responsible for using onfree() to release the memory when it is no longer needed.
ptr | [in] pointer returned by a Get...() or Grow() call to this ON_Workspace. |
FILE* ON_Workspace::OpenFile | ( | const char * | filename, |
const char * | filemode | ||
) |
Uses ON::OpenFile to open a file. ~ON_Workspace will close the file.
filename | [in] name of file |
filemode | [in] open mode (just like second argument to fopen). |
~ON_Workspace will close the file.
FILE* ON_Workspace::OpenFile | ( | const wchar_t * | filename, |
const wchar_t * | filemode | ||
) |
Uses ON::OpenFile to open a file. ~ON_Workspace will close the file.
filename | [in] name of file |
filemode | [in] open mode (just like second argument to _wfopen). |
~ON_Workspace will close the file.