Results 1 to 3 of 3

Thread: Allocation Granularity

  1. #1

    Thread Starter
    Frenzied Member yrwyddfa's Avatar
    Join Date
    Aug 2001
    Location
    England
    Posts
    1,253

    Allocation Granularity

    I need help!

    I am implementing file mappings, and I don't really understand what the Allocation Granularity is.

    Firstly I don't want to view the full file. I only want to view the parts of the file I am interesting in. For instance there is a header, index, and body. Intially a process will be looking at the header, and index in order to determine whereabouts in the body to get the information I actually want from. The file is also going to be around 6Mb so copy Maps would seem to be very expensive (the view is copied into the processes memory location?)

    Anyway I use SYSTEM_INFO to get the allocation granularity of the system, but I don't know how to transform this information into a file byte offset; specifically the high, and low order offsets required by the MapViewOfFile function

    Help!

    Yr

  2. #2
    jim mcnamara
    Guest
    [code]
    lpMapAddress = MapViewOfFile(hMapFile, // handle to mapping object
    FILE_MAP_ALL_ACCESS, // read/write permission
    0, // high-order 32 bits of file offset
    dwFileMapStart, // low-order 32 bits of file offset
    dwMapViewSize); // number of bytes to map
    [code]

    This is C code to make the call. Think of high order & low order
    as two long that are in a union with a long long (if you know C)

    In the real world:

    Make the calculation on a long variable. If the offset value is less than &HFFFFFFFF (you won't overflow the long) or about 2+ billion (US billions), then the high order 32 bits are zero.

    In practical terms, bag it. Always put the offset in the lower 32, 0 in the upper, and don't worry about it. Just check FileLen, and if it's too big, tell the user to forget it. Aside from the fact that mapping a 5+ gig file into memory will trash most PC's anyway, it is not practical.

  3. #3

    Thread Starter
    Frenzied Member yrwyddfa's Avatar
    Join Date
    Aug 2001
    Location
    England
    Posts
    1,253
    You're a star, cheers.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width