[gmx-developers] Re: snew/sfree functions

Erik Lindahl lindahl at stanford.edu
Wed Jun 12 23:13:38 CEST 2002


Valentin Gogonea wrote:
> Thanks again Erik,
> 
> Are snew/sfree functions part of gnu C or they are defined in gromacs. I 
> could not find there definition, it looks like they perform memory 
> allocation/deallocation. Is that correct?
> 

They are Gromacs-specific and perform secure memory allocation. In 
theory you should always check that the pointer you get from malloc() 
isn't NULL (meaning the allocation failed), but since nobody ever does
that these routines check that the allocation was successful, and if not
they stop the execution with an error message telling you the line/file
where the allocation failed. I highly recommend them, although malloc 
will still work of course...

You don't have to calculate the size of the memory you need either; if 
'p' is a pointer of a certain type (e.g. to a struct) you can allocate 
'n' units and let 'p' point to it with the command

snew(p,n);

Actually it is a bunch of macros - the definitions are in smalloc.h.

Cheers,

Erik




More information about the gromacs.org_gmx-developers mailing list