Skip to content
Permalink
Browse files

QgsMalloc, QgsCalloc, QgsFree

  • Loading branch information
blazek committed Oct 9, 2012
1 parent 65141e2 commit 5f2a6a75fea7a70296a91ba0d35f1adb4352c5b0
0 scripts/astyle-all.sh 100644 → 100755
No changes.
0 scripts/astyle-rollback.sh 100644 → 100755
No changes.
0 scripts/astyle.sh 100644 → 100755
No changes.
@@ -21,6 +21,7 @@
#endif
#include <QCoreApplication>
#include "qgsconfig.h"
#include "qgslogger.h"

#include <ogr_api.h>

@@ -104,3 +105,38 @@ QString QGis::tr( QGis::UnitType unit )
{
return QCoreApplication::translate( "QGis::UnitType", qPrintable( toLiteral( unit ) ) );
}

void *QgsMalloc( size_t size )
{
if ( size == 0 || long( size ) < 0 )
{
QgsDebugMsg( QString( "Negative or zero size %1." ).arg( size ) );
return NULL;
}
void *p = malloc( size );
if ( p == NULL )
{
QgsDebugMsg( QString( "Allocation of %1 bytes failed." ).arg( size ) );
}
return p;
}

void *QgsCalloc( size_t nmemb, size_t size )
{
if ( nmemb == 0 || long( nmemb ) < 0 || size == 0 || long( size ) < 0 )
{
QgsDebugMsg( QString( "Negative or zero nmemb %1 or size %2." ).arg( nmemb ).arg( size ) );
return NULL;
}
void *p = QgsMalloc( nmemb * size );
if ( p != NULL )
{
memset( p, 0, nmemb * size );
}
return p;
}

void QgsFree( void *ptr )
{
free( ptr );
}
@@ -21,6 +21,7 @@
#include <QEvent>
#include <QString>
#include <QMetaType>
#include <stdlib.h>
#include <cfloat>
#include <cmath>
#include <qnumeric.h>
@@ -172,6 +173,25 @@ inline bool doubleNearSig( double a, double b, int significantDigits = 10 )
qRound( ar * pow( 10.0, significantDigits ) ) == qRound( br * pow( 10.0, significantDigits ) ) ;
}

/** Allocates size bytes and returns a pointer to the allocated memory.
Works like C malloc() but prints debug message by QgsLogger if allocation fails.
@param size size in bytes
*/
void *QgsMalloc( size_t size );

/** Allocates memory for an array of nmemb elements of size bytes each and returns
a pointer to the allocated memory. Works like C calloc() but prints debug message
by QgsLogger if allocation fails.
@param nmemb number of elements
@param size size of element in bytes
*/
void *QgsCalloc( size_t nmemb, size_t size );

/** Frees the memory space pointed to by ptr. Works like C free().
@param ptr pointer to memory space
*/
void QgsFree( void *ptr );

/** Wkt string that represents a geographic coord sys
* @note added in 1.8 to replace GEOWkt
*/

0 comments on commit 5f2a6a7

Please sign in to comment.
You can’t perform that action at this time.