J
Joe Estock
I have been tinkering with this project that stores data into binary files.
The ammount of records that it stores is not known at compile-time. For
example, refer to the ZIP file structure. There is basically a header
describing each of the files and their location in the file, followed by the
actual contents of those files.
My header looks something like this:
struct myStruct {
UINT uiNumItems;
UINT *pStart;
UINT *pSize;
}
uiNumItems is the total number of items that will be stored in the custom
binary file (let's say for the moment that they are png files). pStart is
the starting location in my custom binary file where the particular png file
is written, and pSize is the filesize of that png image.
What I would like to do is the following:
myStruct ms;
int nNumItems = 20;
ms.pStart = new UINT[nNumItems];
ms.pSize = new UINT[nNumItems];
(here I will set the contents of my struct)
(now i will write that struct to a binary file)
delete[] ms.pStart;
delete[] ms.pSize;
My question is this: Is this the most elegant way to do this? I want to
implement a way to do this with the least ammount of overhead possible.
Additionally, am I making proper use of new and delete[]?
Thanks in advance
The ammount of records that it stores is not known at compile-time. For
example, refer to the ZIP file structure. There is basically a header
describing each of the files and their location in the file, followed by the
actual contents of those files.
My header looks something like this:
struct myStruct {
UINT uiNumItems;
UINT *pStart;
UINT *pSize;
}
uiNumItems is the total number of items that will be stored in the custom
binary file (let's say for the moment that they are png files). pStart is
the starting location in my custom binary file where the particular png file
is written, and pSize is the filesize of that png image.
What I would like to do is the following:
myStruct ms;
int nNumItems = 20;
ms.pStart = new UINT[nNumItems];
ms.pSize = new UINT[nNumItems];
(here I will set the contents of my struct)
(now i will write that struct to a binary file)
delete[] ms.pStart;
delete[] ms.pSize;
My question is this: Is this the most elegant way to do this? I want to
implement a way to do this with the least ammount of overhead possible.
Additionally, am I making proper use of new and delete[]?
Thanks in advance