DIPlib Documentation - ©1995-2015 Quantitative Imaging Group, Delft University of Technology.

# ResourcesNew

Allocate a resource tracking structure

## SYNOPSIS

dip_Error dip_ResourcesNew( resources, noItems )

## FUNCTION

This function allocates a `dip_Resources` structure. The resource structure can be used to register various resources as they are allocated, provided that the allocating function allows you to register the resource. All resources allocated in this manner can be freed with a single call to `ResourcesFree`. Examples of functions supporting this registration scheme are `ImageNew` and special versions of the memory allocation routines.

Some operations consist of an initialization and a cleanup stage. These stages are often performed by separate routines to allow the user to execute his/her own operations in between. In DIPlib there usually is no directly callable cleanup function. Instead the initialization routine registers its cleanup routine with a `dip_Resources` structure provided by the user. The cleanup operation is invoked through `ResourcesFree`.

All functions that support the registration leave you the choice not to register the resource. This is indicated by supplying a zero instead of a resource tracking structure, unless documented otherwise. The `noItems` parameters can be used to give the routine a hint about the number of resources you will register. The structure grows automagically whenever more resources are registered than indicated by the hint parameter.

## ARGUMENTS

Data type | Name | Description
`dip_Resources *` | `resources` | This will be used to return a dip_Resources structure
`dip_int` | `noItems` | A hint about the number of resources you are planning to allocate. This parameter must be >= 2 or 0 to indicate you want the default value. By the way, don't worry too much about this parameter, because when the structure turns out to be too small, it will automatically be expanded

## SEE ALSO

`ResourcesFree`, `ResourcesMerge`, `ResourceSubscribe`, `ResourceUnsubscribe`, `MemoryNew`