Re: Memory Management Question
Michael Barton <[email protected]> Tue, 20 Sep 2005 22:56:15 -0500
| Newsgroups | gmane.games.devel.mud.rom |
|---|---|
| Message-ID | <[email protected]> |
If you want to use malloc/free, you probably can. Just make sure you don't mix it with ROM's alloc_mem/free_mem. I've heard that the idea of ROM's memory pooling is to avoid memory fragmentation, and it's also probably faster than the system's malloc/free. Some newer OS's are implementing better memory pooling with malloc, but I haven't really looked at them. The cheap and easy way to use ROM's pooling is to use alloc_mem and free_mem as you would normally use malloc and free. This is inefficient for permanently-allocated items, since the size of the memory block actually allocated is rounded up to the nearest power of 2. The other way is to set up a new free_list. Basically instead of freeing the memory, it keeps a linked list of the "freed" items, and when you go to allocate a new one it just pulls one off that list. This is more memory efficient than the previous method, since alloc_mem allocates memory in generic sized blocks usually bigger than you need. It also gives you a good place to handle the freeing of individual items in structs. --Palrich. On 9/20/05, [email protected] <[email protected]> wrote: > > > Hello! > > I want to add some linked lists to my characters for Role Play notes. > > I have a question about this: > > When I make my nodes that will be put on the characters, I have to use malloc, > calloc, etc, to allocate my own memory. Then I have to do all of the freeing > myself since I am not using a "free_list" (Such as the room_index_free list for > room indicies)? > > I think I am right because I was reading memory.txt in fastrom and it said that > instead of using free, it keeps track of a list of old zeroed out instances of > whatever is on the list (ie: areas, rooms, mobs, etc). > > My final question is: for anything that does not use the "free_list" I have to > do it the way I described above (assuming if I am right!) > > THANKS! > > > > ---------------------------------------------------------------- > This message was sent using IMP, the Internet Messaging Program. > -- > ROM mailing list > [email protected] > Unsubscribe here ->>> http://www.rom.org/cgi-bin/mailman/listinfo/rom > -- ROM mailing list [email protected] Unsubscribe here ->>> http://www.rom.org/cgi-bin/mailman/listinfo/rom