![]() |
| | #1 |
| uh oh Join Date: Jan 2005 Location: Ontario, CA
Posts: 66
| Programming library with built in manager I have a quick question, but I feel I need to explain things in a bit of detail prior to the actual question. My next project is going to be requiring the use of a memory manager of sorts, what I would like to do is to create a library that contains this manager and providing the developer with a series of "wrapper" functions (basically just providing access to the appropriate dynamic allocation functions with additional support for the memory management operations). To implement the memory manager, I was thinking of implementing a class that handled these operations and providing access to the "wrapper" functions to this class through the means of a global variable visible to only the "inside" of the library. Just for example purposes, the following is a sample of the way the inside of the library will be setup: Code: // appropriate includes here
MemoryManager* myMemory;
int InitManager() { myMemory=new MemoryManager(...); }
int NewMemory(...) { /* do some stuff here */ }
// etc.
Any input would be great! I guess I could implement it and see, but I would rather not have to spend the time to implement the entire library just to find that out. |
| cyreon is offline | |
| | #2 |
| and the hat of vanishing Join Date: Aug 2001 Location: The edge of the known universe
Posts: 21,214
| For example, calling malloc from multiple places, or indeed multiple threads isn't an issue. Done right, it won't be an issue for you either.
__________________ If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut. Up to 8Mb PlusNet broadband from only £5.99 a month! |
| Salem is offline | |
| | #3 |
| uh oh Join Date: Jan 2005 Location: Ontario, CA
Posts: 66
| Thanks Salem. I realize that calling malloc from multiple sources isn't an issue, but in terms of libraries a program includes the code before compile time only once. Would it be safe to assume that the global variables visible to only the code inside the library would also only exist once even in the context of a multithreaded environment? I haven't done a lot of work using global variables inside of libraries, just tend to make a series of functions for a specific purpose usually. |
| cyreon is offline | |
| | #4 |
| and the hat of vanishing Join Date: Aug 2001 Location: The edge of the known universe
Posts: 21,214
| Yes, you'll only have one instance of that global, and only you will be able to see it. Or at least it's easy to arrange things so that will be the case.
__________________ If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut. Up to 8Mb PlusNet broadband from only £5.99 a month! |
| Salem is offline | |
| | #5 |
| Guest Join Date: Aug 2001
Posts: 4,923
| >> myMemory=new MemoryManager(...); Hmm, looks like you'll need a memory manager for that memory manager. ![]() Seriosly, though, if you're using C++ you don't need one - use a smart pointer. |
| Sebastiani is offline | |
| | #6 |
| uh oh Join Date: Jan 2005 Location: Ontario, CA
Posts: 66
| Salem, thanks once again. Sebastiani, lol... not entirely. This isn't a true memory manager, though it does provide some features that assist with memory management of sorts. Mainly intended to maintain a series of records of all dynamically allocated memory blocks for guaranteed removal at the termination of a program, just in case one here or there gets forgotten about. |
| cyreon is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| What's an import library? | chiefmonkey | C++ Programming | 1 | 06-19-2009 05:00 PM |
| Property Set Library (PSL) - Announcement | vultur_gryphus | Projects and Job Recruitment | 0 | 05-29-2008 06:04 AM |
| Makefile for a library | sirmoreno | Linux Programming | 5 | 06-04-2006 04:52 AM |
| very weird .h problem | royuco77 | C++ Programming | 1 | 09-11-2005 07:55 AM |
| better c string functions | samps005 | C Programming | 8 | 11-04-2003 01:28 PM |