IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jun 23, 2005, 11:19:45 AM (21 years ago)
Author:
Paul Price
Message:

Clarified policy on signed/unsigned for memory allocation; psAlloc checks the allocation size against PS_MEM_LIMIT

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/doc/pslib/psLibSDRS.tex

    r4365 r4368  
    1 %%% $Id: psLibSDRS.tex,v 1.294 2005-06-23 03:06:32 price Exp $
     1%%% $Id: psLibSDRS.tex,v 1.295 2005-06-23 21:19:45 price Exp $
    22\documentclass[panstarrs,spec]{panstarrs}
    33
     
    547547\code{NULL}.  If no free function is set, \code{psMemGetDeallocator}
    548548shall return \code{NULL}.
     549
     550\paragraph{Negative allocations}
     551
     552Note that we have specified that the memory size is unsigned
     553(\code{size_t}), so that we can address the full range of memory that
     554the architecture will allow, and to match the behaviour of the system
     555\code{malloc}.  This creates the potential for problems if a negative
     556value is inadvertently passed to \code{psAlloc} --- it will be
     557interpreted as a very large positive value.  To guard against this, we
     558specify that \code{psAlloc} must check that the allocation is less
     559than \code{PS_MEM_LIMIT} (a preprocessor variable).
     560
     561For array-like collections (specifically, \code{psArray},
     562\code{psVector}, and \code{psImage}) we allow the user to refer to a
     563negative index to mean address from the end.  Consequently, the number
     564of elements in structures should be signed.  It is the responsibility
     565of these structure allocators (e.g., \code{psArrayAlloc}) to check
     566that the requested number of elements is not negative (calling
     567\code{psAbort} otherwise).  All other allocators shall simply use
     568size_t where the number of elements is needed (saving the trouble of
     569checking before passing to psAlloc).
    549570
    550571\subsubsection{Callback Routines}
Note: See TracChangeset for help on using the changeset viewer.