mirror of
https://github.com/Unidata/netcdf-c.git
synced 2024-12-09 08:11:38 +08:00
ccc70d640b
and https://github.com/Unidata/netcdf-c/issues/708 Expand the NC_INMEMORY capabilities to support writing and accessing the final modified memory. Three new functions have been added: nc_open_memio, nc_create_mem, and nc_close_memio. The following new capabilities were added. 1. nc_open_memio() allows the NC_WRITE mode flag so a chunk of memory can be passed in and be modified 2. nc_create_mem() allows the NC_INMEMORY flag to be set to cause the created file to be kept in memory. 3. nc_close_mem() allows the final in-memory contents to be retrieved at the time the file is closed. 4. A special flag, NC_MEMIO_LOCK, is provided to ensure that the provided memory will not be freed or reallocated. Note the following. 1. If nc_open_memio() is called with NC_WRITE, and NC_MEMIO_LOCK is not set, then the netcdf-c library will take control of the incoming memory. This means that the original memory block should not be freed but the block returned by nc_close_mem() must be freed. 2. If nc_open_memio() is called with NC_WRITE, and NC_MEMIO_LOCK is set, then modifications to the original memory may fail if the space available is insufficient. Documentation is provided in the file docs/inmemory.md. A test case is provided: nc_test/tst_inmemory.c driven by nc_test/run_inmemory.sh WARNING: changes were made to the dispatch table for the close entry. From int (*close)(int) to int (*close)(int,void*).
46 lines
1.1 KiB
C
46 lines
1.1 KiB
C
/*! \file netcdf_mem.h
|
|
*
|
|
* Main header file for in-memory (diskless) functionality.
|
|
*
|
|
* Copyright 2010 University Corporation for Atmospheric
|
|
* Research/Unidata. See COPYRIGHT file for more info.
|
|
*
|
|
* See \ref copyright file for more info.
|
|
*
|
|
*/
|
|
|
|
#ifndef NETCDF_MEM_H
|
|
#define NETCDF_MEM_H 1
|
|
|
|
#include <netcdf.h>
|
|
|
|
typedef struct NC_memio {
|
|
size_t size;
|
|
void* memory;
|
|
#define NC_MEMIO_LOCKED 1 /* Do not try to realloc or free provided memory */
|
|
int flags;
|
|
} NC_memio;
|
|
|
|
#if defined(__cplusplus)
|
|
extern "C" {
|
|
#endif
|
|
|
|
/* Treate a memory block as a file; read-only */
|
|
EXTERNL int nc_open_mem(const char* path, int mode, size_t size, void* memory, int* ncidp);
|
|
|
|
EXTERNL int nc_create_mem(const char* path, int mode, size_t initialsize, int* ncidp);
|
|
|
|
/* Alternative to nc_open_mem with extended capabilites
|
|
See docs/inmemory.md
|
|
*/
|
|
EXTERNL int nc_open_memio(const char* path, int mode, NC_memio* info, int* ncidp);
|
|
|
|
/* Close memory file and return the final memory state */
|
|
EXTERNL int nc_close_memio(int ncid, NC_memio* info);
|
|
|
|
#if defined(__cplusplus)
|
|
}
|
|
#endif
|
|
|
|
#endif /* NETCDF_MEM_H */
|