Changeset 6065b3aa for doc


Ignore:
Timestamp:
Jun 1, 2017, 10:58:18 PM (7 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
49c9773
Parents:
6016c87
Message:

second attempt at memory-allocation routines

File:
1 edited

Legend:

Unmodified
Added
Removed
  • doc/user/user.tex

    r6016c87 r6065b3aa  
    1111%% Created On       : Wed Apr  6 14:53:29 2016
    1212%% Last Modified By : Peter A. Buhr
    13 %% Last Modified On : Tue May 30 11:45:46 2017
    14 %% Update Count     : 2098
     13%% Last Modified On : Thu Jun  1 22:46:09 2017
     14%% Update Count     : 2126
    1515%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    1616
     
    52425242\begin{description}
    52435243\item[fill]
    5244 after allocation the storage is or is not filled with a specified character.
     5244after allocation the storage is filled with a specified character.
    52455245\item[resize]
    52465246an existing allocation is decreased or increased in size.
    52475247In either case, new storage may or may not be allocated and, if there is a new allocation, as much data from the existing allocation is copied.
    5248 For an increase in storage size, new storage after the copied data may or may not be filled.
     5248For an increase in storage size, new storage after the copied data may be filled.
    52495249\item[alignment]
    52505250an allocation starts on a specified memory boundary, e.g., an address multiple of 64 or 128 for cache-line purposes.
    52515251\item[array]
    52525252the allocation size is scaled to the specified number of array elements.
    5253 An array may or not be filled, resized, or aligned.
     5253An array may be filled, resized, or aligned.
    52545254\end{description}
    5255 
    5256 The following table show the allocation routines supporting different combinations of storage-management capabilities:
     5255The table shows allocation routines supporting different combinations of storage-management capabilities:
    52575256\begin{center}
    5258 \begin{tabular}{@{}r|l|l|l|l@{}}
    5259                                         & fill                          & resize        & alignment     & array \\
     5257\begin{tabular}{@{}lr|l|l|l|l@{}}
     5258                &                                       & \multicolumn{1}{c|}{fill}     & resize        & alignment     & array \\
    52605259\hline
    5261 ©malloc©                        & no/yes                        & no/yes        & no            & no    \\
    5262 ©amalloc©                       & no/copy data/yes      & no/yes        & no            & yes   \\
    5263 ©calloc©                        & yes (0 only)          & no            & no            & yes   \\
    5264 ©realloc©                       & no/copy data          & yes           & no            & no    \\
    5265 ©memalign©                      & no/yes                        & no            & yes           & no    \\
    5266 ©amemalign©                     & no/yes                        & no            & yes           & yes   \\
    5267 ©align_alloc©           & no                            & no            & yes           & no    \\
    5268 ©posix_memalign©        & no                            & no            & yes           & no    \\
     5260C               & ©malloc©                      & no                    & no            & no            & no    \\
     5261                & ©calloc©                      & yes (0 only)  & no            & no            & yes   \\
     5262                & ©realloc©                     & no/copy               & yes           & no            & no    \\
     5263                & ©memalign©            & no                    & no            & yes           & no    \\
     5264                & ©posix_memalign©      & no                    & no            & yes           & no    \\
     5265C11             & ©aligned_alloc©       & no                    & no            & yes           & no    \\
     5266\CFA    & ©alloc©                       & no/copy/yes   & no/yes        & no            & yes   \\
     5267                & ©align_alloc©         & no/yes                & no            & yes           & yes   \\
    52695268\end{tabular}
    52705269\end{center}
    5271 % When ©amalloc© resizes and fills, the space after the copied data from the source is set to the fill character.
    52725270It is impossible to resize with alignment because the underlying ©realloc© allocates storage if more space is needed, and it does not honour alignment from the original allocation.
    52735271
    52745272\leavevmode
    52755273\begin{cfa}[aboveskip=0pt,belowskip=0pt]
    5276 // allocation, non-array types
    5277 forall( dtype T | sized(T) ) T * malloc( void );§\indexc{malloc}§
    5278 forall( dtype T | sized(T) ) T * malloc( char fill );
    5279 
    5280 // allocation, array types
    5281 forall( dtype T | sized(T) ) T * calloc( size_t dim );§\indexc{cmalloc}§
    5282 forall( dtype T | sized(T) ) T * amalloc( size_t dim );§\indexc{amalloc}§  // alternate name for calloc
    5283 forall( dtype T | sized(T) ) T * amalloc( size_t dim, char fill );
    5284 
    5285 // resize, non-array types
    5286 forall( dtype T | sized(T) ) T * realloc( T * ptr, size_t size );§\indexc{realloc}§
    5287 forall( dtype T | sized(T) ) T * realloc( T * ptr, size_t size, char fill );
    5288 forall( dtype T | sized(T) ) T * malloc( T * ptr, size_t size );  // alternate name for realloc
    5289 forall( dtype T | sized(T) ) T * malloc( T * ptr, size_t size, char fill );
    5290 
    5291 // resize, array types
    5292 forall( dtype T | sized(T) ) T * amalloc( T * ptr, size_t dim );
    5293 forall( dtype T | sized(T) ) T * amalloc( T * ptr, size_t dim, char fill );
    5294 
    5295 // alignment, non-array types
    5296 forall( dtype T | sized(T) ) T * memalign( size_t alignment );§\indexc{memalign}§
    5297 forall( dtype T | sized(T) ) T * memalign( size_t alignment, char fill );
    5298 forall( dtype T | sized(T) ) T * aligned_alloc( size_t alignment );§\indexc{aligned_alloc}§
    5299 forall( dtype T | sized(T) ) int posix_memalign( T ** ptr, size_t alignment );§\indexc{posix_memalign}§
    5300 
    5301 // alignment, array types
    5302 forall( dtype T | sized(T) ) T * amemalign( size_t alignment, size_t dim );§\indexc{amemalign}§
    5303 forall( dtype T | sized(T) ) T * amemalign( size_t alignment, size_t dim, char fill );
    5304 
    5305 // data, non-array types
     5274// C unsafe allocation
     5275extern "C" { void * mallac( size_t size ); }§\indexc{memset}§
     5276extern "C" { void * calloc( size_t dim, size_t size ); }§\indexc{calloc}§
     5277extern "C" { void * realloc( void * ptr, size_t size ); }§\indexc{realloc}§
     5278extern "C" { void * memalign( size_t align, size_t size ); }§\indexc{memalign}§
     5279extern "C" { int posix_memalign( void ** ptr, size_t align, size_t size ); }§\indexc{posix_memalign}§
     5280
     5281// §\CFA§ safe equivalents, i.e., implicit size specification
     5282forall( dtype T | sized(T) ) T * malloc( void );
     5283forall( dtype T | sized(T) ) T * calloc( size_t dim );
     5284forall( dtype T | sized(T) ) T * realloc( T * ptr, size_t size );
     5285forall( dtype T | sized(T) ) T * memalign( size_t align );
     5286forall( dtype T | sized(T) ) T * aligned_alloc( size_t align );
     5287forall( dtype T | sized(T) ) int posix_memalign( T ** ptr, size_t align );
     5288
     5289// §\CFA§ safe general allocation, fill, resize, array
     5290forall( dtype T | sized(T) ) T * alloc( void );§\indexc{alloc}§
     5291forall( dtype T | sized(T) ) T * alloc( char fill );
     5292forall( dtype T | sized(T) ) T * alloc( size_t dim );
     5293forall( dtype T | sized(T) ) T * alloc( size_t dim, char fill );
     5294forall( dtype T | sized(T) ) T * alloc( T ptr[], size_t dim );
     5295forall( dtype T | sized(T) ) T * alloc( T ptr[], size_t dim, char fill );
     5296
     5297// §\CFA§ safe general allocation, align, fill, array
     5298forall( dtype T | sized(T) ) T * align_alloc( size_t align );
     5299forall( dtype T | sized(T) ) T * align_alloc( size_t align, char fill );
     5300forall( dtype T | sized(T) ) T * align_alloc( size_t align, size_t dim );
     5301forall( dtype T | sized(T) ) T * align_alloc( size_t align, size_t dim, char fill );
     5302
     5303// C unsafe initialization/copy
     5304extern "C" { void * memset( void * dest, int c, size_t size ); }
     5305extern "C" { void * memcpy( void * dest, const void * src, size_t size ); }
     5306
     5307// §\CFA§ safe initialization/copy
    53065308forall( dtype T | sized(T) ) T * memset( T * dest, char c );§\indexc{memset}§
    53075309forall( dtype T | sized(T) ) T * memcpy( T * dest, const T * src );§\indexc{memcpy}§
    53085310
    5309 // data, array types
    5310 forall( dtype T | sized(T) ) T * amemset( T * dest, size_t dim, char c );§\indexc{amemset}§
    5311 forall( dtype T | sized(T) ) T * amemcpy( T * dest, const T * src, size_t dim );§\indexc{amemcpy}§
    5312 
    5313 // allocation/deallocation and constructor/destructor
    5314 forall( dtype T, ttype Params | sized(T) | { void ?{}(T *, Params); } ) T * new( Params p );§\indexc{new}§
     5311// §\CFA§ safe initialization/copy array
     5312forall( dtype T | sized(T) ) T * memset( T dest[], size_t dim, char c );
     5313forall( dtype T | sized(T) ) T * memcpy( T dest[], const T src[], size_t dim );
     5314
     5315// §\CFA§ allocation/deallocation and constructor/destructor
     5316forall( dtype T | sized(T), ttype Params | { void ?{}( T *, Params ); } ) T * new( Params p );§\indexc{new}§
    53155317forall( dtype T | { void ^?{}( T * ); } ) void delete( T * ptr );§\indexc{delete}§
    5316 forall( dtype T, ttype Params | { void ^?{}( T * ); void delete(Params); } ) void delete( T * ptr, Params rest );
     5318forall( dtype T, ttype Params | { void ^?{}( T * ); void delete( Params ); } )
     5319  void delete( T * ptr, Params rest );
     5320
     5321// §\CFA§ allocation/deallocation and constructor/destructor, array
     5322forall( dtype T | sized(T), ttype Params | { void ?{}( T *, Params ); } ) T * anew( size_t dim, Params p );§\indexc{anew}§
     5323forall( dtype T | sized(T) | { void ^?{}( T * ); } ) void adelete( size_t dim, T arr[] );§\indexc{adelete}§
     5324forall( dtype T | sized(T) | { void ^?{}( T * ); }, ttype Params | { void adelete( Params ); } )
     5325  void adelete( size_t dim, T arr[], Params rest );
    53175326\end{cfa}
    53185327
Note: See TracChangeset for help on using the changeset viewer.