Re: [AD] Netiquette? [OFF TOPIC]

From: Sammy (samedi@DHC.NET)
Date: 05/19/98

I try to stay out of these discussions, but I'd just like to point out

Somebody I don't recall said:

>Do you have to know how to fix your car to drive it? NO.

If you want it fixed, you pay through the nose

>Do you have to know how to build your house to live in it? NO.

If you want it built, or improved, you pay through the nose.

>Do you have to know how to code to "Run" a mud? NO.

When you're ready to pay through the nose for circle coding, I'm
qualified, willing, and available on short notice.  Contact me via private
email for hourly or by the job rates.  Oh, and if you need automotive work
or simple home repair, I can do those too, although not as well.  I'll do
those cheap (if your expectations are suitably low).


I was just kicking around the idea of a simple memory management wrapper.
I don't think it would be anything fancy, just a simple addition to track
and catagorize memory usage, automate some of the error handling, and
offer a little protection.  Here's a little mailer code to illustrate:

#define MAGIC_MEM_NUMBER 214    /* for detecting overruns */

#define MEM_UNKNOWN     0
#define MEM_CHAR        1       /* PC/NPC stuff         */
#define MEM_OBJ         2       /* object memory        */
#define MEM_ROOMS       3       /* room memory          */
/* etc */

struct mem_block_data {
  void *data;
  int type;
  int size;
  struct mem_block_data *next;

#define CREATE(result, type, number, memtype) do {
        if(!(result = (type *) alloc_mem((number) * sizeof((type)), \
        (memtype)) { perror("malloc failure"); \
        syslog("file: %s, line: %d", \
        __FILE__, __LINE__); abort(); } } while(0)

#define FREE(data)  do { if(!free_mem((data))) { \
        syslog("SYSERR": Attempt to free unallocated memory in file:" \
               " %s, line: %d", __FILE__, __LINE__); } } while(0)

void *alloc_mem(size_t size, int type)
  struct mem_block_data *memptr;

  memptr = alloc_mem_block();   /* add to the mem_block queue */

  if(!(memptr->data = malloc(size + 1)))
    return NULL;

  *memptr->data = (byte) MAGIC_MEM_NUM;
  memptr->type = type;
  memptr->size = size;

  return memptr->data + 1;

int free_mem(void *data)
  struct mem_block_data *memptr;

  if(!(memptr = find_mem_block(data)))
    return 0;


  return 1;

I was thinking it'd be handy to have a period check of all memory blocks
to make sure all the magic numbers are intact, and also an imm funciton
that reports memory usage by type.  If you have lots of types you can get
some very detailed reporting.

There really isn't that much more code to be written.  The hard part is
fixing all the existing CREATE's (if you want usage reporting, which was
my original purpose for this).  The free's could be changed with search
and replace if all the CREATE's are done.

Any thoughts on this?

p.s. The above code is free of charge ;)

     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     | |

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