158bool CSG_Grid::_Memory_Create(
bool bCached)
167 if( bCached || _Cache_Check() )
169 return( _Cache_Create() );
172 return( _Array_Create() );
176void CSG_Grid::_Memory_Destroy(
void)
182 _Cache_Destroy(
false);
196bool CSG_Grid::_Array_Create(
void)
202 if( (m_Values = (
void **)
SG_Malloc(
Get_NY() *
sizeof(
void *))) != NULL )
206 char *pLine = (
char *)m_Values[0];
228void CSG_Grid::_Array_Destroy(
void)
247#define CACHE_FILE_POS(x, y) (m_Cache_Offset + (m_Cache_bFlip ? Get_NY() - 1 - y : y) * m_nBytes_Line + x * m_nBytes_Value)
250#if defined(_SAGA_LINUX)
251#define CACHE_FILE_SEEK fseek
253#define CACHE_FILE_SEEK _fseeki64
262 || _Cache_Create(m_Cache_File , m_Type, m_Cache_Offset, m_Cache_bSwap, m_Cache_bFlip)
269 return( !
is_Cached() || _Cache_Destroy(
true) );
278bool CSG_Grid::_Cache_Check(
void)
288 s.
Printf(
"%s\n%s\n%s: %.2fMB",
289 _TL(
"Shall I activate file caching for new grid."),
291 _TL(
"Total memory size"),
312 if( !m_System.is_Valid() || m_Type != Data_Type || !
SG_File_Exists(File) )
317 if( (m_Cache_Stream = fopen(File,
"r+b")) == NULL
318 && (m_Cache_Stream = fopen(File,
"rb" )) == NULL )
324 m_Cache_bTemp =
false;
325 m_Cache_Offset = Offset;
327 m_Cache_bFlip = bFlip;
335bool CSG_Grid::_Cache_Create(
void)
344 if( (m_Cache_Stream = fopen(File,
"w+b")) == NULL )
350 m_Cache_bTemp =
true;
352 m_Cache_bSwap =
false;
353 m_Cache_bFlip =
false;
359 fwrite(m_Values ? m_Values[y] : Values.Get_Array(), 1,
Get_nLineBytes(), m_Cache_Stream);
370bool CSG_Grid::_Cache_Destroy(
bool bMemory_Restore)
374 if( bMemory_Restore && _Array_Create() && !
CACHE_FILE_SEEK(m_Cache_Stream, m_Cache_Offset, SEEK_SET) )
382 char *pValue = (
char *)m_Values[y];
395 fclose(m_Cache_Stream);
397 m_Cache_Stream = NULL;
416void CSG_Grid::_Cache_Set_Value(
int x,
int y,
double Value)
448double CSG_Grid::_Cache_Get_Value(
int x,
int y)
const
void SG_UI_Msg_Add_Error(const char *Message)
bool SG_UI_Process_Set_Ready(void)
bool SG_UI_Process_Set_Progress(int Position, int Range)
bool SG_UI_Dlg_Continue(const CSG_String &Message, const CSG_String &Caption)
SAGA_API_DLL_EXPORT bool SG_File_Exists(const CSG_String &FileName)
SAGA_API_DLL_EXPORT void * SG_Malloc(size_t size)
SAGA_API_DLL_EXPORT void SG_Free(void *memblock)
SAGA_API_DLL_EXPORT CSG_String SG_File_Make_Path(const CSG_String &Directory, const CSG_String &Name)
SAGA_API_DLL_EXPORT bool SG_File_Delete(const CSG_String &FileName)
SAGA_API_DLL_EXPORT void * SG_Calloc(size_t num, size_t size)
SAGA_API_DLL_EXPORT bool SG_Dir_Exists(const CSG_String &Directory)
SAGA_API_DLL_EXPORT CSG_String SG_File_Get_Name_Temp(const CSG_String &Prefix)
#define SG_FREE_SAFE(PTR)
const SG_Char * Get_File_Name(bool bNative=true) const
const SG_Char * Get_Name(bool bShort=true)
sLong Get_NCells(void) const
bool is_Cached(void) const
int Get_nValueBytes(void) const
int Get_nLineBytes(void) const
static CSG_String Format(const char *Format,...)
int Printf(const char *Format,...)
SAGA_API_DLL_EXPORT sLong SG_Grid_Cache_Get_Threshold(void)
SAGA_API_DLL_EXPORT int SG_Grid_Cache_Get_Mode(void)
SAGA_API_DLL_EXPORT const SG_Char * SG_Grid_Cache_Get_Directory(void)
static int gSG_Grid_Cache_Mode
const SG_Char * SG_Grid_Cache_Get_Directory(void)
void SG_Grid_Cache_Set_Threshold(int nBytes)
int SG_Grid_Cache_Get_Mode(void)
void SG_Grid_Cache_Set_Threshold_MB(double nMegabytes)
static CSG_String gSG_Grid_Cache_Directory
sLong SG_Grid_Cache_Get_Threshold(void)
double SG_Grid_Cache_Get_Threshold_MB(void)
#define CACHE_FILE_POS(x, y)
static sLong gSG_Grid_Cache_Threshold
void SG_Grid_Cache_Set_Mode(int Mode)
void SG_Grid_Cache_Set_Directory(const SG_Char *Directory)