Re: Memory Wrapper

From: George (greerga@CIRCLEMUD.ORG)
Date: 05/21/98


On Thu, 21 May 1998, Sammy wrote:

>The structure I use looks to be about 16 bytes at the moment.  A hash
>table is a very good idea.  Do you hash by address?

I shrank it down to 20 bytes for just memory, but decided the whole generic
attack for memory and buffers was best.  It currently hashes by the size of
the buffer you request.

>I was thinking I'll probably start out by changing the CREATE macro to
>call my new allocation function with the MEM_UNKOWN type.  Then I can
>add CREATE_CHAR macros and make changes a few at a time.  It may be worth

I changed the CREATE() macro.  I suppose adding more types would be
possible, and easy.

>it just to have the check for bad free() calls and periodic magic number
>checks.  It'd also be nice to be able to write new code with a unique
>MEM_TYPE to make check for memory problems while the code is still fresh.

I use a generic 'magic_check()' function to validate the buffer.  Currently
it makes sure the buffer hasn't been overwritten.

>I think I'll be adding a check_sanity() function that will check for
>overruns or invalid pointers on demand for a single pointer.

Yup, I can attest to it being a good idea.

>> Not totally necessary.  If something is allocated in 'parse_object', well,
>> you know what it is. :)
>
>Is there a portable way to know the current function?

Not really, but I change __FUNCTION__ to __FILE__ with a #define if not
using GNU CC. The file and line is enough for my purposes, yours would
require the extra types.

>I'm probably going to try throwing this together and installing it in
>stock pl12 to get an idea of how it'll work out.  I don't think I'd want
>to use this fulltime, but I think it would be very useful as a
>compile-time debugging option, and would be great to use on new code for a
>month or two after writing it.

I use it all the time since I've almost finished my version 1.8 of it.
Boot times with -c, averaged, in cache, on Pentium 133 (dual).

Stock CircleMUD: 1.6 seconds.
Buffer v1.8    : 1.8 seconds.
Buffer v1.7    : 30 seconds.

I was tired of it booting like a slug.

>If you put a lock bit on the structure (maybe a negative memblock->type)
>it might also be useful as a quick and dirty way of making data thread
>safe, although the supporting code would be a lot of work.

Already done. :)

--
George Greer, greerga@circlemud.org | Genius may have its limitations, but
http://patches.van.ml.org/          | stupidity is not thus handicapped.
http://www.van.ml.org/CircleMUD/    |                  -- Elbert Hubbard


     +------------------------------------------------------------+
     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     | http://democracy.queensu.ca/~fletcher/Circle/list-faq.html |
     +------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 12/15/00 PST