Welcome! Log In Create A New Profile

Advanced

How to load file into ram

Posted by Matando 
How to load file into ram
October 11, 2008 05:13PM
I'm trying get a program I'm creating to load a file into ram. Now I'm not sure if LibFat or the memcpy call does this so can someone explain to me with some example code how to load a file into ram.

also can someone tell me how much ram the wii has, I looked it up on google but everything I found says different.
Re: How to load file into ram
October 11, 2008 08:53PM
What, loading a file in ram ? You're speaking about load a file into a variable ?
If yes, use fread(); =)
Re: How to load file into ram
October 11, 2008 09:16PM
void* loadFileContents( char* fileName, int fileLength )
{
	void* myBuffer;
	FILE* inputFile;

	inputFile = fopen( fileName, "rb");
	myBuffer = malloc(fileLength);
	fread( myBuffer, 1, fileLength, inputFile);
	fclose(inputFile);
	return myBuffer;
}

I can't remember the code to find the file length, but something like this will dynamically read the file in. Don't forget to deallocate the space after you're finished :-)



Edited 1 time(s). Last edit at 10/13/2008 10:05AM by whodares.
Re: How to load file into ram
October 12, 2008 07:37AM
Determining file size is simple enough as long as you're not working with streams that you can't seek in (on Wii, you're almost certainly not):
int pos = ftell(File);
fseek(File, 0, SEEK_END);
size = ftell(File);
fseek(File, pos, SEEK_SET); //return to previous position
Re: How to load file into ram
October 13, 2008 09:18AM
Whodares' routine will indeed happily load a file into RAM but never return a pointer or anything to the data. (add return myBuffer to the end of the function). Also, dont forget to free() your buffers when you're done with them.
Re: How to load file into ram
October 13, 2008 09:45AM
Quote
blasty
Whodares' routine will indeed happily load a file into RAM but never return a pointer or anything to the data

lol, good call, I never even noticed that :-P

Updated it now.



Edited 1 time(s). Last edit at 10/13/2008 10:05AM by whodares.
Re: How to load file into ram
October 16, 2008 12:25AM
lol sorry for the late reply, thanks guys :)
Sorry, only registered users may post in this forum.

Click here to login