Skip to main content
gamedev.net
🔒 Locked

mapviewoffile question

Started by gorgorath Jan 15, 2007 at 4:49 AM 1 replies 750+ views
Original Post
gorgorath
gorgorath
Hi i have some problems with mapping files, i store my data in blocks the following xyz, xyz, xyz, rgb, rgb, rgb, rgb, normals, normals, normals, normals in this case 4 vertices each with xyz, rgb, and a normal now i map the file in memory, to stream as fast as possible HANDLE hFm = MapViewOfFile(reinterpret_cast (fileHandle), dwDesiredAccess, dwFileOffsetHigh, dwFileOffsetLow, dwNumberOfBytesToMap ); // cout << GetLastError() << endl; i can map the whole file into memory by setting dwOffsetHigh and low to NULL, but this is not what i want, because there is some level of detail going on. i want to read the first 2 points of xyz, and say normals this requires me to offset the fileHighOffset and fileLowOffset, i've been reading documents but they are talking about system granularity etc. all that i want is a function that i can set the current pointer to in this case the normal block and read #bytes from there any links, help tutorials Tia Paul
Cosmic Keys to my Creations & Times
Stevieboy
Stevieboy
Hi, MapViewOfFile returns a pointer, all you need to do is increment it.


MyVertex *pVertex = NULL;

pVertex = (MyVertex*)MapViewOfFile(
filemapping, FILE_MAP_WRITE, //FILE_MAP_ALL_ACCESS,
0, 0, 0);


MyVertex v1 = *pVertex;
pVertex++; //increment the pointer.

MyVertex v2 = *pVertex;


You can use any type you want for the pointer.

edit.
um helps if I read the question properly ;).

Why can't you just get your types as whole types as I mentioned above, and then just get the values you want? I think the fileoffsethigh and fileoffsetlow are for reading or mapping large chunks of a file. (I think?), you could have a massive pak file or audio file or something, so you would only want to map certain parts at a time.
LessBread
LessBread
As Stevieboy points out, if the file isn't huge it's easier to map the whole thing and manipulate the resulting pointer. By huge I mean hundreds of megabytes. If you want to learn more about how to deal with that situation, you can find a pretty good tutorial on the subject here. Look for the articles on Memory Techniques. If you want to learn more about allocation granularity, check out Why is address space allocation granularity 64K?, Common File Mapping Problems and Platform Differences, and Creating a View Within a File.
"I thought what I'd do was, I'd pretend I was one of those deaf-mutes." - the Laughing Man

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.