3
<title>Matrix allocation - GNU Scientific Library -- Reference Manual</title>
4
<meta http-equiv="Content-Type" content="text/html">
5
<meta name="description" content="GNU Scientific Library -- Reference Manual">
6
<meta name="generator" content="makeinfo 4.8">
7
<link title="Top" rel="start" href="index.html#Top">
8
<link rel="up" href="Matrices.html#Matrices" title="Matrices">
9
<link rel="next" href="Accessing-matrix-elements.html#Accessing-matrix-elements" title="Accessing matrix elements">
10
<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
12
Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 The GSL Team.
14
Permission is granted to copy, distribute and/or modify this document
15
under the terms of the GNU Free Documentation License, Version 1.2 or
16
any later version published by the Free Software Foundation; with the
17
Invariant Sections being ``GNU General Public License'' and ``Free Software
18
Needs Free Documentation'', the Front-Cover text being ``A GNU Manual'',
19
and with the Back-Cover Text being (a) (see below). A copy of the
20
license is included in the section entitled ``GNU Free Documentation
23
(a) The Back-Cover Text is: ``You have freedom to copy and modify this
24
GNU Manual, like GNU software.''-->
25
<meta http-equiv="Content-Style-Type" content="text/css">
26
<style type="text/css"><!--
27
pre.display { font-family:inherit }
28
pre.format { font-family:inherit }
29
pre.smalldisplay { font-family:inherit; font-size:smaller }
30
pre.smallformat { font-family:inherit; font-size:smaller }
31
pre.smallexample { font-size:smaller }
32
pre.smalllisp { font-size:smaller }
33
span.sc { font-variant:small-caps }
34
span.roman { font-family:serif; font-weight:normal; }
35
span.sansserif { font-family:sans-serif; font-weight:normal; }
41
<a name="Matrix-allocation"></a>
42
Next: <a rel="next" accesskey="n" href="Accessing-matrix-elements.html#Accessing-matrix-elements">Accessing matrix elements</a>,
43
Up: <a rel="up" accesskey="u" href="Matrices.html#Matrices">Matrices</a>
47
<h4 class="subsection">8.4.1 Matrix allocation</h4>
49
<p>The functions for allocating memory to a matrix follow the style of
50
<code>malloc</code> and <code>free</code>. They also perform their own error
51
checking. If there is insufficient memory available to allocate a vector
52
then the functions call the GSL error handler (with an error number of
53
<code>GSL_ENOMEM</code>) in addition to returning a null pointer. Thus if you
54
use the library error handler to abort your program then it isn't
55
necessary to check every <code>alloc</code>.
58
— Function: gsl_matrix * <b>gsl_matrix_alloc</b> (<var>size_t n1, size_t n2</var>)<var><a name="index-gsl_005fmatrix_005falloc-879"></a></var><br>
59
<blockquote><p>This function creates a matrix of size <var>n1</var> rows by <var>n2</var>
60
columns, returning a pointer to a newly initialized matrix struct. A new
61
block is allocated for the elements of the matrix, and stored in the
62
<var>block</var> component of the matrix struct. The block is “owned” by the
63
matrix, and will be deallocated when the matrix is deallocated.
64
</p></blockquote></div>
67
— Function: gsl_matrix * <b>gsl_matrix_calloc</b> (<var>size_t n1, size_t n2</var>)<var><a name="index-gsl_005fmatrix_005fcalloc-880"></a></var><br>
68
<blockquote><p>This function allocates memory for a matrix of size <var>n1</var> rows by
69
<var>n2</var> columns and initializes all the elements of the matrix to zero.
70
</p></blockquote></div>
73
— Function: void <b>gsl_matrix_free</b> (<var>gsl_matrix * m</var>)<var><a name="index-gsl_005fmatrix_005ffree-881"></a></var><br>
74
<blockquote><p>This function frees a previously allocated matrix <var>m</var>. If the
75
matrix was created using <code>gsl_matrix_alloc</code> then the block
76
underlying the matrix will also be deallocated. If the matrix has been
77
created from another object then the memory is still owned by that
78
object and will not be deallocated.
79
</p></blockquote></div>