root/juggler/tags/1.0.5/SharedMem/vjMemPoolWin32.h

Revision 7539, 4.2 kB (checked in by anonymous, 7 years ago)

This commit was manufactured by cvs2svn to create tag
'RELENG_1_0_5_RELEASE'.

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