I'm writing a program that has a listbox with several items in it. Each item has a representing text that will be shown in a multiline edit control when selecting an item in the listbox. The text length is not static. I'm currently saving the all texts in several small textfiles, but I want to store all of them in one large file instead. This is not a very big problem, but its gets tricky when I want to delete one item in the middle of the list, or when I want to change the text.

What would be the easiest way of achieving this? I was thinking of using an ini file, but I'm not sure if that is the best alternative.
Posted on 2003-08-23 12:35:39 by Delight
What about (This is the easiest way) just appending it always to the end, mark deleted parts with a flag and upon exit rewrite the text file completely while skipping the flagged parts?
Posted on 2003-08-23 13:17:39 by JimmyClif
Thats a very good idea. Thank you!
Posted on 2003-08-23 15:50:37 by Delight
Hmm.:rolleyes:

What if the file is really big, lets say several hundered mb?

Is there no possibility to use the os file fragmenting system?
So you could also handle files with less free disk space.
Posted on 2003-08-24 12:39:39 by TCT

Hmm.:rolleyes:

What if the file is really big, lets say several hundered mb?

Is there no possibility to use the os file fragmenting system?
So you could also handle files with less free disk space.

Doesn't matter if the file is 2 byte or 2 TB, windows will frament the poor file any way (I **hate** windows for it's inabillity to avoid framgemting files (not even half teh disk is full, still, +200 fragmented files -- and it wasn't long time ago I derfragmented the disk!))
Posted on 2003-08-24 12:52:53 by scientica
You'r right, windows need a lot of patience.:grin:

But what I mean is if it is possible to delete a block from within a file without copying the whole file to a new location on disk.
In this case I want to fragment the file manually.
Posted on 2003-08-24 13:24:00 by TCT
I don't think you can.

Hmm, that's a nice idea actually if I ever make an OS
Posted on 2003-08-24 13:51:44 by Sephiroth3
the way i have seen some companies do the list type thing is this way and i have used it also


''
the ]' with a return charectors would be ]',0dh,0ah you can this way detect groups by finding the value
then you make sure each group has a double return and lok for 0dh,0ah,0d,0ah,'[ so once you find that
you know how many byte the groups area is... this will help you later

then the sub groups look like this

SUB_GROUP = "
so then you look for 20h,3Dh,20h,22h then you fallow backwards until you find 0dh,0ah know you know you sub ;groups name size and you can grab it...

then there is the leaf that is right after the sub group them together looks like this

SUB_GROUP = "LEAF";

you also already know from that last look up where the leaf starts so now its time to find the end so look for ";,0dh,0ah

know you know the size of you text area and location and can use it...

when you looked earlyer you found the size of the group well if you rememberd to record the offset then you know where it starts and it loops back to the same process

i also forgot you mention the first step is to grab the groups name lol but i figured with the examples above it would be aparent.

using common sence and some know how you can make this work very well..
Posted on 2003-08-24 15:26:24 by devilsclaw
Thanks, devilsclaw, but I have already solved most of my problems using this way:






The yellow colored blocks are item headers:



ItemHeader struct
ITEMOFFSET dd ?
ITEMSIZE dd ?
ItemHeader ends



The green block at the end of the file is a main header with some general info:


Header struct
ITEMCOUNT dd ?
SIZEOFHEADERS dd ?
Header ends





I have added functions to add a new item and to get the data back. Now I need a function to delete an item. That means that I will have to move all data in the file, after the deleted item, backwards. I have to do this in several small steps and my question is:

How much memory is it safe to allocate for the moving process?

64kB? 1MB? 10MB?


I hope you understand my question and that I have explained everything corectly (I'm veeeery tired)
Posted on 2003-08-25 15:42:12 by Delight
well when i was working with memory... i relized even though i allocated 10mb it did not allocate any more then a cetrain amount until it actually needed more.
Posted on 2003-08-25 17:53:41 by devilsclaw
Originally posted by Delight
Each item has a representing text that will be shown in a multiline edit control when selecting an item in the listbox. The text length is not static. I'm currently saving the all texts in several small textfiles, but I want to store all of them in one large file instead. This is not a very big problem, but its gets tricky when I want to delete one item in the middle of the list, or when I want to change the text.

What would be the easiest way of achieving this?
The answer is very simple: use XML, it does exactly what you want it to do. And it is very easy to write a custom parser for it.
Posted on 2003-08-26 06:26:09 by sluggy