i want to make a custom menu for on my desktop. I want the menu to read its shortcuts from a *.txt file (extension doesnt matter, will make it a custom one anyways).
what would the best way be to read the info inside the file? i was thinking about using the ReadFile api but i dont know if this is a good methode for reading files.

(format of the files will be simple, kinda like how delphi stores its controls, before an item i use 1 byte to tell the length of the string after that byte, and maybe i reserve a second byte for propertys but that doesnt matter)
Posted on 2004-11-06 11:18:31 by Scorpie
I guess the best way to do such thing is to read file's content once and all. You will have to read file's size, allocate this amount of memory, and pass this file's size again to the ReadFile api.

It is the best way, because you use api only once, after it it's only your code that deals with the data from the file, so it's only your task to accelerate it.

If you would call apis more often, you would see the program is slower. It is due to file i/o operations and also thanks to microsoft for their slow code :wink:
Posted on 2004-11-06 11:27:58 by Reverend
allocating memory and then writing a files content to it, then i can acces the data also directly? that would defenatly save me a lot of ReadFile calls.
Posted on 2004-11-06 11:32:30 by Scorpie
that would defenatly save me a lot of ReadFile calls.

You can get rid of ReadFile completely using memory mapped file access.
Memory mapped file is virtually loaded to memory and read on demand by swapping mechanism, which is as effective as reading the whole file to allocated buffer. Big advantage for read-only files is that when more instances of your application is running simultaneously, all instances share only one buffer.
You will need these API calls:

And for unloading:
Posted on 2004-11-07 12:32:15 by vit$oft
thanks for the reply but does it have any speed advantages on allocating a file and using ReadFile api, because i wont run my app twice at the same time, it will be a menu for shotcuts, more an cunstom shaped and programmed start-menu so it never runs twice since there is no point in running it twice.
the file to read will contain info about the menu structure (which shortcuts, what submenu's etc etc).
Posted on 2004-11-07 15:54:08 by Scorpie