mirror of
https://github.com/qgis/QGIS.git
synced 2025-10-06 00:07:29 -04:00
QgsMalloc, QgsCalloc, QgsFree
This commit is contained in:
parent
65141e29ee
commit
5f2a6a75fe
0
scripts/astyle-all.sh
Normal file → Executable file
0
scripts/astyle-all.sh
Normal file → Executable file
0
scripts/astyle-rollback.sh
Normal file → Executable file
0
scripts/astyle-rollback.sh
Normal file → Executable file
0
scripts/astyle.sh
Normal file → Executable file
0
scripts/astyle.sh
Normal file → Executable file
@ -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
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user