Thread: system calls in linux

  1. #16
    Eager young mind
    Join Date
    Jun 2006
    Posts
    342
    well, the thing is, lets say I am using primary indexing method. That means, my index file contains two fields.
    1) the primary key field value.
    2) The pointer to the block containing the record corresponding to the value.
    Both my index file and my data file are sorted with respect to the primary key field value.
    My data file is stored over many disc blocks.
    So, if I need to retrieve a record whose promary key value is known, I need to do a binary search on the index file to find out which disc block can hold the record that I am interested in. For this,I need the pointer to that block. Now that I have the pointer, I can load that block to the memory and retrieve the tuple.

    So, disk is of relevance here as I cant store my entire data file in the memory.I can only load parts of it as and when required.
    In the middle of difficulty, lies opportunity

  2. #17
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    What exactly do you think mmap actually does for you?

    If your file is really that big that it would not fit in memory, then mmap would fail.

    It's really no different to allocating a big array yourself, then reading the whole file into memory. Once there, you can treat it as any other array in memory, and if it is sorted for example, then you can search it with bsearch().

    Maybe practice doing this with regular files before thinking about trying to use mmap.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #18
    Eager young mind
    Join Date
    Jun 2006
    Posts
    342
    Ok, for the time being forget about the mmap() question that I had initially asked. Is there a system call that allows me to detect the block size on my disc?
    In the middle of difficulty, lies opportunity

  4. #19
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Probably (or maybe), but again, what does the physical (or logical) block size have to do with anything?

    Your data has a record size of 's'
    you get to the 'n'th record by doing fseek( fp, s * n, SEEK_SET );

    Then you read the record by doing
    fread( &rec, 1, sizeof rec, fp );

    Voila.

    Just let the OS worry about which disk block(s) your record maps to.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #20
    Eager young mind
    Join Date
    Jun 2006
    Posts
    342
    well,the requirement is that the node size in my B+ tree is of the size of the block . So, I need to get the block size. also, I am compelled to work on windows, so, I have to find out if there is one such call for windows.
    In the middle of difficulty, lies opportunity

  6. #21
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Unless the size is already pretty close to say 512 or 4096, it sounds like an awful waste of space.

    > also, I am compelled to work on windows,
    So why is this posted in the Linux forum, and why are you using mmap(), which isn't available on windows AFAIK.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  7. #22
    Eager young mind
    Join Date
    Jun 2006
    Posts
    342
    >Unless the size is already pretty close to say 512 or 4096,
    Thats what even I was speculating. But my prof told me so. He said I have to use a system call to ascertain the actual block size. Do you think MS releases the list of such available system calls that are avaialble for developers? Are you aware of any such links?

    >it sounds like an awful waste of space.
    Really? I can have many data pointers in one node right? So, instead of having a large number of small nodes, I have few nodes that are as large as my disc block

    >So why is this posted in the Linux forum, and why are you using mmap(), which isn't available on windows AFAIK.
    well, I had started off on linux, but I had to switch as my teammates arent that familiar with linux.
    In the middle of difficulty, lies opportunity

  8. #23
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Random example which has something to do with disk sizes
    http://msdn.microsoft.com/library/de...ogicaldisk.asp
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  9. #24
    Eager young mind
    Join Date
    Jun 2006
    Posts
    342
    well, thanks for that ..
    IS it true that I need to have the cygwin library installed to execute system calls from within my C program in windows?
    In the middle of difficulty, lies opportunity

  10. #25
    Eager young mind
    Join Date
    Jun 2006
    Posts
    342
    It does have a data type of "uint64" for the blocksize.
    Can you tell me how do I actually use this. I have not scripted in windows before.
    In the middle of difficulty, lies opportunity

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. compiling linux file system
    By Hoshangi in forum Linux Programming
    Replies: 1
    Last Post: 08-13-2008, 10:35 PM
  2. system calls
    By kiai_viper in forum Networking/Device Communication
    Replies: 7
    Last Post: 06-13-2007, 11:34 AM
  3. System calls stopping my function ...
    By twomers in forum C++ Programming
    Replies: 1
    Last Post: 06-20-2006, 09:01 AM
  4. Dabbling with Linux.
    By Hunter2 in forum Tech Board
    Replies: 21
    Last Post: 04-21-2005, 04:17 PM