root/juggler/tags/1.0.7/SharedMem/vjMemPoolWin32.h
| Revision 8789, 4.3 kB (checked in by patrickh, 7 years ago) | |
|---|---|
| |
| Line | |
|---|---|
| 1 | /*************** <auto-copyright.pl BEGIN do not edit this line> ************** |
| 2 | * |
| 3 | * VR Juggler is (C) Copyright 1998, 1999, 2000, 2001, 2002 |
| 4 | * by Iowa State University |
| 5 | * |
| 6 | * Original Authors: |
| 7 | * Allen Bierbaum, Christopher Just, |
| 8 | * Patrick Hartling, Kevin Meinert, |
| 9 | * Carolina Cruz-Neira, Albert Baker |
| 10 | * |
| 11 | * This library is free software; you can redistribute it and/or |
| 12 | * modify it under the terms of the GNU Library General Public |
| 13 | * License as published by the Free Software Foundation; either |
| 14 | * version 2 of the License, or (at your option) any later version. |
| 15 | * |
| 16 | * This library is distributed in the hope that it will be useful, |
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 19 | * Library General Public License for more details. |
| 20 | * |
| 21 | * You should have received a copy of the GNU Library General Public |
| 22 | * License along with this library; if not, write to the |
| 23 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
| 24 | * Boston, MA 02111-1307, USA. |
| 25 | * |
| 26 | * ----------------------------------------------------------------- |
| 27 | * File: $RCSfile$ |
| 28 | * Date modified: $Date$ |
| 29 | * Version: $Revision$ |
| 30 | * ----------------------------------------------------------------- |
| 31 | * |
| 32 | *************** <auto-copyright.pl END do not edit this line> ***************/ |
| 33 | |
| 34 | |
| 35 | #ifndef _MemPoolWin32_h_ |
| 36 | #define _MemPoolWin32_h_ |
| 37 | //---------------------------------------------- |
| 38 | // vjMemPoolWin32 |
| 39 | // |
| 40 | // Purpose: |
| 41 | // Shared Memory pool on the win32 systems |
| 42 | // Used by vjMemory (Base class) to control allocation |
| 43 | // and deallocation from a "memory pool" |
| 44 | // |
| 45 | // Use: |
| 46 | // Clients should create memory pools as needed |
| 47 | // Then when objects are created, they can pass |
| 48 | // a pool as a parameter to the new (if the object |
| 49 | // is a derived from vjMemory) |
| 50 | // |
| 51 | // NOTE: |
| 52 | // The static function 'init' MUST be called before |
| 53 | // any forks or other process splitting take place. |
| 54 | // This is because it sets static data that must |
| 55 | // be shared across processes. |
| 56 | // |
| 57 | // Author: |
| 58 | // Andy Himberger |
| 59 | // |
| 60 | // Date: 11-6-97 |
| 61 | //----------------------------------------------- |
| 62 | |
| 63 | #include <vjConfig.h> |
| 64 | #include <stdio.h> |
| 65 | #include <windows.h> |
| 66 | |
| 67 | |
| 68 | |
| 69 | class vjMemPoolWin32 : public vjMemPool |
| 70 | { |
| 71 | public: |
| 72 | vjMemPoolWin32(size_t initialSize = 65536, int numProcs = 8, char* staticTempName = "memPoolWin32XXXXXX") { |
| 73 | std::cerr << "\nvjMemPoolWin32: Allocating arena (" |
| 74 | << initialSize << " bytes, " |
| 75 | << numProcs << " procs" |
| 76 | << ")\n" << std::flush; |
| 77 | } |
| 78 | |
| 79 | virtual ~vjMemPoolWin32() { |
| 80 | std::cerr << "\nUnlinking: " << std::endl; |
| 81 | } |
| 82 | |
| 83 | public: |
| 84 | virtual void* allocate(size_t size) |
| 85 | { |
| 86 | void* retval; |
| 87 | retval = malloc(size); |
| 88 | |
| 89 | if (retval == NULL) |
| 90 | std::cerr << "MemPoolWin32: Out of memory!!!" << std::endl; |
| 91 | |
| 92 | return retval; |
| 93 | } |
| 94 | |
| 95 | virtual void* reallocate(void* ptr, size_t size) |
| 96 | { |
| 97 | void* retval; |
| 98 | retval = realloc(ptr,size); |
| 99 | std::cerr << "MemPoolWin32: realloc failure" << std::endl; |
| 100 | |
| 101 | return retval; |
| 102 | } |
| 103 | |
| 104 | virtual void deallocate(void* ptr) |
| 105 | { |
| 106 | free(ptr); |
| 107 | } |
| 108 | |
| 109 | public: // Non-virtual functions |
| 110 | |
| 111 | |
| 112 | public: |
| 113 | // Function must be called before any vjMemPools are created. |
| 114 | // Automatically called by the first new with default values if not called |
| 115 | // previously |
| 116 | // Function to initialize any STATIC data structures |
| 117 | static void init(size_t initialSize = 32768, int numProcs = 64, |
| 118 | char* staticTempName = "/var/tmp/memPoolsArenaXXXXXX") |
| 119 | { |
| 120 | std::cerr << "\nvjMemPoolWin32: Allocating Base Arena for ALL " |
| 121 | << "vjMemPoolWin32's.\n " |
| 122 | << initialSize << " bytes, " |
| 123 | << numProcs << " procs" |
| 124 | << "\n" << std::flush; |
| 125 | } |
| 126 | |
| 127 | void* operator new(size_t sz) |
| 128 | { |
| 129 | std::cerr << "MemPoolWin32::new called.\n"; |
| 130 | //if (arenaForMemPools == NULL) |
| 131 | // init(); // Make sure that we are initialized already. |
| 132 | |
| 133 | return malloc(sizeof(vjMemPoolWin32)); |
| 134 | } |
| 135 | |
| 136 | void operator delete(void* ptr) |
| 137 | { |
| 138 | free(ptr); |
| 139 | } |
| 140 | private: |
| 141 | void* arena; |
| 142 | char* arenaFileName; |
| 143 | |
| 144 | private: // Static data for all members -- Must be set before forks!!!! |
| 145 | static void* arenaForMemPools; |
| 146 | static char* arenaForMemPoolsFileName; |
| 147 | }; |
| 148 | |
| 149 | |
| 150 | #endif |
Note: See TracBrowser for help on using the browser.
