Moving large amounts of data

I know that in stdio.h there is a function 'fread()' for reading a number of bytes from a file directly into an array. Are there any other ways of moving lots of data, especially any ways inherent to the language, and not held in libraries?

Specifically what I want is a fast, tidy solution to having a large array that can be reset any time, and whose initial value is essentially particular at every index.

Otherwise I'll probably end up creating a temp file.
I don't think I understand your question (but my brain is on the fritz right now...)

If you want to interact with files you must use some form of library --either C or C++, or OS-specific, or third-party (like Boost filesystem).

What do you mean by:
1) resetting an array?
2) particular initial values for every index?
Fast, tidy solution to having a large array: T *array=new T[n];
Actually I'm using C right now, not C++.

And what I mean is...

I have an array. And it's starting value is specific, i.e. not all 0's or '\0's or anything, but a certain pattern. At intervals I need to reset it to this initial value.

I know that I could write the whole array to a file, and use fread() to transfer the data from that file to my array, but I would prefer a method that doesn't use files, but just another block of RAM.

The first simple solution would be to loop through, element by element, copying them from one to the other, but my array is of char's, so this would be extremely slow. I could conceivably copy four of them at a time with proper casting, given processors' word length of 4 bytes, but I suspect there may be an even speedier solution or trick.

Or at least, I'm hoping, lol.
I think a simple iterative loop is fine. Most modern compilers should pipeline those instructions so they are done in groups anyways.
You could cast the pointer to long * and copy word by word. You should of course be careful if the length is not divisible by 4, 8, or whatever.

EDIT: What am I saying? If you need to keep a copy of the original array, why not just use memcpy()?
Last edited on
Sweet, thanks. That's exactly the sort of thing I was looking for.
Topic archived. No new replies allowed.