This is the mail archive of the cygwin@sourceware.cygnus.com mailing list for the Cygwin project.
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
system:
WindowsNT 4.0 service pack 5
PIII 550
128mb ram
command-line listing:
I:\PROJECTS\core\core_ms_app>gcc -o main.exe main.cxx -I../template -I../factory
..\\template\\core_pool.h: In method `void * ::core::Pool<T>::alloc(size_t)':
In file included from main.cxx:4:
..\\template\\core_pool.h:51: parse error before `::'
..\\template\\core_pool.h:71: parse error before `&'
..\\template\\core_pool.h: In method `void ::core::Pool<T>::free(void *)':
..\\template\\core_pool.h:76: parse error before `;'
..\\template\\core_pool.h: In method `::core::Pool<T>::~Pool()':
..\\template\\core_pool.h:85: parse error before `('
[main] d:\cygnus\CYGWIN~1\H-I586~1\lib\gcc-lib\i586-cygwin32\egcs-2.91.57\cc1plu
s.exe 1002 (0) handle_exceptions: Exception: STATUS_ACCESS_VIOLATION
[main] cc1plus 1002 (1) handle_exceptions: Dumping stack trace to cc1plus.exe.co
re
I:\PROJECTS\core\core_ms_app>gcc -o main.exe main.cxx -I../template -I../factory
..\\template\\core_pool.h: In method `void * ::core::Pool<T>::alloc(size_t)':
In file included from main.cxx:4:
..\\template\\core_pool.h:51: parse error before `::'
..\\template\\core_pool.h:71: parse error before `&'
..\\template\\core_pool.h: In method `void ::core::Pool<T>::free(void *)':
..\\template\\core_pool.h:76: parse error before `;'
..\\template\\core_pool.h: In method `::core::Pool<T>::~Pool()':
..\\template\\core_pool.h:85: parse error before `('
[main] d:\cygnus\CYGWIN~1\H-I586~1\lib\gcc-lib\i586-cygwin32\egcs-2.91.57\cc1plu
s.exe 1002 (0) handle_exceptions: Exception: STATUS_ACCESS_VIOLATION
[main] cc1plus 1002 (0) handle_exceptions: Dumping stack trace to cc1plus.exe.co
re
cc1plus.exe.core:
[main] cc1plus 1002 (0) exception: trapped!
[main] cc1plus 1002 (0) exception: code 0xC0000005 at 0x45FAAD
[main] cc1plus 1002 (0) exception: ax 0x0 bx 0x1F5 cx 0x2EC dx 0x0
[main] cc1plus 1002 (0) exception: si 0x25DF5AC di 0x1 bp 0x25DFD1C sp 0x25DF470
[main] cc1plus 1002 (0) exception: exception is: STATUS_ACCESS_VIOLATION
[main] cc1plus 1002 (0) stack: Stack trace:
[main] cc1plus 1002 (0) stack: frame 0: sp = 0x25DF284, pc = 0x6100A2C3
[main] cc1plus 1002 (0) stack: frame 1: sp = 0x25DF2C0, pc = 0x77F94846
[main] cc1plus 1002 (0) stack: frame 2: sp = 0x25DF2E4, pc = 0x77F89013
[main] cc1plus 1002 (0) stack: frame 3: sp = 0x25DF370, pc = 0x77F76392
[main] cc1plus 1002 (0) stack: frame 4: sp = 0x25DFD1C, pc = 0x48FB85
[main] cc1plus 1002 (0) stack: frame 5: sp = 0x25DFD48, pc = 0x49328B
[main] cc1plus 1002 (0) stack: frame 6: sp = 0x25DFDA0, pc = 0x61004402
[main] cc1plus 1002 (0) stack: frame 7: sp = 0x25DFF88, pc = 0x61004420
[main] cc1plus 1002 (0) stack: frame 8: sp = 0x25DFF94, pc = 0x5B26CE
[main] cc1plus 1002 (0) stack: frame 9: sp = 0x25DFFA4, pc = 0x40103A
[main] cc1plus 1002 (0) stack: frame 10: sp = 0x25DFFC0, pc = 0x77F1BA3C
[main] cc1plus 1002 (0) stack: frame 11: sp = 0x25DFFF0, pc = 0x0
[main] cc1plus 1002 (0) stack: End of stack trace
core_pool.h:
/*************************************
(C)opyright 2000 Christopher Nelson, All Rights Reserved
********/
#ifndef __CoreMemoryPool_header
#define __CoreMemoryPool_header
#include "core_list.h"
/*********************************************************************************************
Pool provides an extrememly fast memory allocation scheme for specific objects. It should
be inherited into the object that you want to use it for, or embedded. operators new and
delete are already overridden for you, however if you embed it you will have to override
them akk by yourself. It also may save you quite a bit of memory over
standard new and delete, if your objects are very small.
Pool follows all new and delete conventions. Pool will only allocate objects of the size
that it is optimized to handle. For all other sizes it refers the request to the global new.
*********************************************************************************************/
namespace core {
template<class T>
class Pool
{
// data structure used for managing pool.
union pool_struct
{
pool_struct *next; //pointer to next block
T object; //reference to object
};
// pointer to head of memory pool
pool_struct *head;
// list used to store blocks of allocated memory for cleanup.
List<pool_struct> blocks;
private:
void *alloc(size_t size)
{
pool_struct *tmp;
if (head == 0)
{
// allocate and initialize a list of fixed-size blocks
union pool_struct *block = static_cast<pool_struct *>::operator new(sizeof(T)*512]),
*p;
// save block for cleanup.
blocks.AddHead(block);
// now link each item together
for(i=0; i<512; i++) {
if (i!=511) block[i].next = &block[i+1]; //link to next block
else block[i].next = 0; // set last one to NULL.
}
head = block;
}
// allocate from the pool.
tmp=head;
head=head->next;
// here's the memory we wanted
return static_cast<void *>&tmp->object;
}
void free (void *mem)
{
pool_struct *m = static_cast<pool_struct *>mem;
m->next = head;
head=m;
}
public:
Pool():head(0) {};
~Pool() { // allows pools to be deallocated
ListIterator it(blocks.Head()); // without causing leaks - we delete
while(it()) { ::operator delete(it, sizeof(T)*512); } // each allocated block of memory.
};
public:
void *operator new(size_t size)
{
if (size != sizeof(T)) // if size is "wrong,"
return ::operator new(size); // have standard operator
// new handle the request
else
return alloc(size);
}
void operator delete(void *mem, size_t size)
{
if (mem==0) return;
if (size != sizeof(T)) { // if size is "wrong,"
::operator delete(mem); // have standard operator delete
return; // handle the request.
}
free(mem);
}
};
}; //end core namespace
#endif // generated Thu Mar 2 16:08:14 2000
<<...>>
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |