opennurbs_memory.c
Go to the documentation of this file.
00001 /* $NoKeywords: $ */
00002 /*
00003 //
00004 // Copyright (c) 1993-2012 Robert McNeel & Associates. All rights reserved.
00005 // OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert
00006 // McNeel & Associates.
00007 //
00008 // THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
00009 // ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
00010 // MERCHANTABILITY ARE HEREBY DISCLAIMED.
00011 //                              
00012 // For complete openNURBS copyright information see <http://www.opennurbs.org>.
00013 //
00015 */
00016 
00017 #include "pcl/surface/3rdparty/opennurbs/opennurbs_system.h"
00018 #include "pcl/surface/3rdparty/opennurbs/opennurbs_defines.h"
00019 #include "pcl/surface/3rdparty/opennurbs/opennurbs_memory.h"
00020 #include "pcl/surface/3rdparty/opennurbs/opennurbs_error.h"
00021 
00022 #if defined(ON_DLL_IMPORTS)
00023 /*
00024 // If you use OpenNURBS as a windows DLL, then define ON_DLL_IMPORTS 
00025 // in applications that use OpenNURBS and they will get onmalloc(), etc.,
00026 // from the DLL.
00027 //
00028 // If you use OpenNURBS as a static library, do not define ON_DLL_IMPORTS.
00029 */
00030 #error opennurbs_memory.c must not be compiled with ON_DLL_IMPORTS defined.
00031 #endif
00032 
00033 ON_MEMORY_POOL* ON_MainMemoryPool(void)
00034 {
00035   return 0;
00036 }
00037 
00038 ON_MEMORY_POOL* ON_WorkerMemoryPool(void)
00039 {
00040   return 0;
00041 }
00042 
00043 void* onmalloc_from_pool( ON_MEMORY_POOL* pool, size_t sz )
00044 {
00045   void* p;
00046   p = (sz > 0) ? malloc(sz) : 0;
00047   return p;
00048 }
00049 
00050 void* onmalloc( size_t sz )
00051 {
00052   return onmalloc_from_pool( 0, sz );
00053 }
00054 
00055 void* oncalloc_from_pool( ON_MEMORY_POOL* pool, size_t num, size_t sz )
00056 {
00057   void* p;
00058   p = (num > 0 && sz > 0) ? calloc(num,sz) : 0;
00059   return p;
00060 }
00061 
00062 void* oncalloc( size_t num, size_t sz )
00063 {
00064   return oncalloc_from_pool( 0, num, sz );
00065 }
00066 
00067 void onfree( void* memblock )
00068 {
00069   if ( 0 != memblock )
00070     free(memblock);
00071 }
00072 
00073 void* onrealloc( void* memblock, size_t sz )
00074 {
00075   return onrealloc_from_pool( 0, memblock, sz );
00076 }
00077 
00078 void* onrealloc_from_pool( ON_MEMORY_POOL* pool, void* memblock, size_t sz )
00079 {
00080   void* p;
00081   
00082   if ( sz <= 0 ) 
00083   {
00084     onfree(memblock);
00085     return 0;
00086   }
00087   
00088   if ( !memblock ) 
00089   {
00090     return onmalloc_from_pool( pool, sz);
00091   }
00092 
00093   p = realloc(memblock,sz);
00094 
00095   return p;
00096 }
00097 
00098 size_t onmsize( const void* memblock )
00099 {
00100   size_t sz = 0;
00101 
00102   if (memblock) 
00103   {
00104 #if defined(ON_COMPILER_MSC)
00105     sz = _msize( (void*)memblock );
00106 #elif defined(ON_COMPILER_XCODE)
00107     sz = malloc_size( (void*)memblock );
00108 #else
00109     // No predictable function exists and
00110     // nothing in core opennurbs code uses
00111     // onmsize().  If you find a portable
00112     // way to support another compiler or 
00113     // platform, then report it to the support
00114     // contact on http://opennurbs.org and
00115     // the code will be added in the next release.
00116     //ON_ERROR("onmsize not implemented on this compiler or platform.");
00117     sz = 0;
00118 #endif
00119   }
00120 
00121   return sz;
00122 }
00123 


pcl
Author(s): Open Perception
autogenerated on Wed Aug 26 2015 15:27:01