Sophie

Sophie

distrib > Mandriva > 2010.0 > i586 > media > contrib-release > by-pkgid > c109337651527e96d7bb9adc83c5b18a > files > 58

libvips-devel-7.18.2-1mdv2010.0.i586.rpm

<!-- manual page source format generated by PolyglotMan v3.2, -->
<!-- available at http://polyglotman.sourceforge.net/ -->

<html>
<head>
<title>IM_ARRAY(3) manual page</title>
</head>
<body bgcolor='white'>
<a href='#toc'>Table of Contents</a><p>

<h2><a name='sect0' href='#toc0'>Name</a></h2>
IM_ARRAY, IM_NEW, IM_NUMBER - memory allocation macros 
<h2><a name='sect1' href='#toc1'>Synopsis</a></h2>

<p> #include
&lt;vips/vips.h&gt; 
<p> type-name *IM_NEW( IMAGE *im, type-name ) <br>
type-name *IM_ARRAY( IMAGE *im, int number, type-name ) <br>
int IM_NUMBER( array ) 
<p> 
<h2><a name='sect2' href='#toc2'>Description</a></h2>

<p> NEW, NUMBER and ARRAY are macros built
on <a href='im_malloc.3.html'>im_malloc(3)</a>
 which make memory allocation slightly easier.  Given a type
name, NEW returns a pointer to a piece of memory large enough to hold an
object of that type. ARRAY works as NEW, but allocates space for a number
of objects. Given an array, NUMBER returns the number of elements in that
array. 
<p>   #define IM_NEW(IM,A) ((A *)im_malloc((IM),sizeof(A)))<br>
   #define IM_NUMBER(R) (sizeof(R)/sizeof(R[0]))<br>
   #define IM_ARRAY(IM,N,T) ((T *)im_malloc((IM),(N) * sizeof(T)))<br>
 
<p> Both IM_ARRAY and IM_NEW take an image descriptor as their first parameter.
Memory is allocated local to this descriptor, that is, when the descriptor
is closed, the memory is automatically freed for you. If you pass NULL instead
of an image descriptor, memory is allocated globally and is not automatically
freed. 
<p> (NOTE: in versions of VIPS before 7.3, <a href='NEW.3.html'>NEW(3)</a>
 and <a href='ARRAY.3.html'>ARRAY(3)</a>
 did not
have the initial IMAGE parameter. If you are converting an old VIPS7.2 program,
you will need to add a NULL parameter to the start of all <a href='NEW.3.html'>NEW(3)</a>
 and <a href='ARRAY.3.html'>ARRAY(3)</a>

parameter lists.) 
<p> Both functions return NULL on error, setting im_errorstring.

<p> Example: 
<p>   #include &lt;vips/vips.h&gt;<br>
 
<p>   /* A structure we want to carry about.<br>
    */<br>
   typedef struct {<br>
     ...<br>
   } Wombat;<br>
 
<p>   /* A static array of them.<br>
    */<br>
   static Wombat swarm[] = {<br>
     { ... },<br>
     { ... },<br>
     { ... }<br>
   };<br>
   static int swarm_size = IM_NUMBER( swarm );<br>
 
<p>   int<br>
   transform_wombat( IMAGE *in, IMAGE *out )<br>
   {<br>
     /* Allocate space for a Wombat.<br>
      */<br>
     Wombat *mar = IM_NEW( out, Wombat );<br>
 
<p>     /* Allocate space for a copy of swarm.<br>
      */<br>
     Wombat *mar = IM_ARRAY( out, swarm_size, Wombat );<br>
 
<p>     ....<br>
   }<br>
 
<p> 
<h2><a name='sect3' href='#toc3'>Copyright</a></h2>
National Gallery, 1993 
<h2><a name='sect4' href='#toc4'>See Also</a></h2>
<a href='im_malloc.3.html'>im_malloc(3)</a>
, <a href='im_open_local.3.html'>im_open_local(3)</a>
.

<h2><a name='sect5' href='#toc5'>Author</a></h2>
J. Cupitt - 23/7/93  <p>

<hr><p>
<a name='toc'><b>Table of Contents</b></a><p>
<ul>
<li><a name='toc0' href='#sect0'>Name</a></li>
<li><a name='toc1' href='#sect1'>Synopsis</a></li>
<li><a name='toc2' href='#sect2'>Description</a></li>
<li><a name='toc3' href='#sect3'>Copyright</a></li>
<li><a name='toc4' href='#sect4'>See Also</a></li>
<li><a name='toc5' href='#sect5'>Author</a></li>
</ul>
</body>
</html>