1

I have a real-time project that have a heavy process on each line of some text file,what do you suggest for storing that text?

what I do now, is to store all the text file in a char* variable, and then work with with that variable, instead of the file, my problem is when the text goes bigger what can I do? and there is possibility to reach the limitation of char array, and memory heap is going to get bigger:(

Another solution I have in mind is that every time I want that particular line of text, I go through the file and read it, and work with it, but this solution makes my program so slow, and as I mention earlier, the time is important for me, what do you guys suggest for it?

Is there another way which is fast enough so that I can use it?

Shaheen Zahedi
  • 1,216
  • 3
  • 15
  • 40
  • You didn't mention which RTOS is used (or yours "realtime" is just "should be fast"). It might have memory mapped files. – KIIV Jul 23 '16 at 06:00
  • @KIIV it is should be fast kind :) – Shaheen Zahedi Jul 23 '16 at 06:02
  • 1
    It really depends on the situation or what the file is. If you want to really help performance and the situation allows, I'd suggest parsing the file ahead of time into a faster internal datastructure rather than as raw text. If the file is huge to the point that memory would be a limitation, I'd suggest parsing it into a database with proper indexes and operating on the database. Either way, I'd definitely suggest at the moment using either a `std::vector` or `std::string` instead of a `char *` if you can. It'll probably make your life a little easier in the short and long runs. – Taywee Jul 23 '16 at 06:14

1 Answers1

0

If it is really large why you wanna store it in the RAM? Use memory mapped file

stryku
  • 722
  • 5
  • 12
  • it is not large at the time, but i have a fear it's gonna get bigger and is memory mapped file faster than variable assignment? – Shaheen Zahedi Jul 23 '16 at 06:02
  • 3
    I would rewrite code only if it is necessary. If now, you're ok with storing whole file in RAM, leave it as it is. What do you mean? Could you provide some use case? – stryku Jul 23 '16 at 06:06