Results 1 to 14 of 14

Thread: Is it possible to memory map a file in Qt

  1. #1
    Join Date
    Jan 2006
    Posts
    31
    Thanked 5 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Is it possible to memory map a file in Qt

    I have googled around but I've found only an old and not Qt APi QMemoryFile Class.

    Thanks
    Marco

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Is it possible to memory map a file in Qt

    Use "mmap()". Memory mapping is not know in Windows world, so there is no point putting it in Qt.

  3. #3
    Join Date
    Jan 2006
    Location
    Kerala
    Posts
    371
    Thanks
    76
    Thanked 37 Times in 32 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Is it possible to memory map a file in Qt

    AFAIK, D-Bus is not available in Windows and Qt seems to have it ?
    We can't solve problems by using the same kind of thinking we used when we created them

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Is it possible to memory map a file in Qt

    Quote Originally Posted by sunil.thaha View Post
    AFAIK, D-Bus is not available in Windows and Qt seems to have it ?
    Ok, specially for you:

    Qt Code:
    1. #include <sys/mman.h>
    2.  
    3. QwwMemoryMapper {
    4. public:
    5. enum Protection { None, Readable, Writable, Executable };
    6. QwwMemoryMapper(QFile &f, int length, int prot, bool shared, int offset){
    7. int protfl=PROT_NONE;
    8. if(prot & Readable) protfl|=PROT_READ;
    9. if(prot & Writable) protfl|=PROT_WRITE;
    10. if(prot & Executable) protfl|=PROT_EXEC;
    11. _pointer = mmap(0, length, protfl, shared ? MAP_SHARED : MAP_PRIVATE, f.handle(), offset);
    12. _length = length;
    13. }
    14.  
    15. ~QwwMemoryMapper(){
    16. munmap(_pointer, _length);
    17. }
    18.  
    19. void *pointer() const { return _pointer; }
    20.  
    21. int mappedLength() const { return _length; }
    22.  
    23. private:
    24. void *_pointer;
    25. int _length;
    26. };
    To copy to clipboard, switch view to plain text mode 

    As for DBUS:
    1. It is being implemented on Windows
    2. It is more than two functions (in contrast to mmap()) so it does make sense to map it to Qt API.

  5. #5
    Join Date
    Jan 2006
    Location
    Kerala
    Posts
    371
    Thanks
    76
    Thanked 37 Times in 32 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Is it possible to memory map a file in Qt

    As for DBUS:
    1. It is being implemented on Windows
    Waw !!, Obvously did not know that. thank u

    2. It is more than two functions (in contrast to mmap()) so it does make sense to map it to Qt API. Today 16:10
    I agree, did not know what memory mapped file just was

    Qt Code:
    1. void *_pointer;
    2. int _length;
    To copy to clipboard, switch view to plain text mode 
    I read somewhere IIRC ( int C++ Coding standard ) , that it is not recommended to use an underscore as a start character ? And the author has not given reason for why it should not be used.

    Just google and found this http://www.doc.ic.ac.uk/lab/cplus/c++.rules/chap5.html
    http://www.cs.cmu.edu/afs/cs.cmu.edu...tyleguide.html
    http://www-hera-b.desy.de/subgroup/s...dingrules.html
    We can't solve problems by using the same kind of thinking we used when we created them

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Is it possible to memory map a file in Qt

    Quote Originally Posted by sunil.thaha View Post
    I read somewhere IIRC ( int C++ Coding standard ) , that it is not recommended to use an underscore as a start character ? And the author has not given reason for why it should not be used.
    Because this might cause name clashes. But it doesn't apply when used in classes because classes provide own namespaces for internal fields, so it won't cause trouble.

    And sorry, but academic rules written by teachers for their students somehow doesn't seem to bother me that much

    It's like with the Pirate Codebook - it's more a list of guidelines than actual rules.

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Is it possible to memory map a file in Qt

    Quote Originally Posted by sunil.thaha View Post
    I read somewhere IIRC ( int C++ Coding standard ) , that it is not recommended to use an underscore as a start character ?
    It isn't recommended, because identifiers that start with underscore and capital letter or another underscore are reserved for the compiler. This is somewhat similar to a rule like "don't use pointers, because you might get a memory leak" --- it's just too defensive.

  8. #8
    Join Date
    Jan 2006
    Location
    Kerala
    Posts
    371
    Thanks
    76
    Thanked 37 Times in 32 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Is it possible to memory map a file in Qt

    Well this is the reply I got from Marsha Cline.

    Glad the C++ FAQ has helped.

    According to the standard, the namespace reserved by the compiler includes identifiers that start with an underscore followed immediately by a capital letter as well as identifiers that contain a double-underscore anywhere within the identifier – beginning, ending, in the middle, anywhere. That means names like __foo or foo__bar or _Foo are bad, but _foo is okay *if* the compiler had no accidental names starting with an underscore followed immediately by a lower-case letter. However I personally avoid leading underscores since I was burned once by a compiler that had erroneously stolen one of those identifiers, so instead I use trailing underscores to indicate member variables.

    Marshall


    We can't solve problems by using the same kind of thinking we used when we created them

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Is it possible to memory map a file in Qt

    The class name is part of the identifier, so in reality those identifiers start with "QwwMemoryMapper". But if you really want to keep then conversation going, then simply run sed -e "s/_/m_/g" on the source code and let's forget about the problem.

  10. #10
    Join Date
    Aug 2006
    Posts
    44
    Thanked 7 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Is it possible to memory map a file in Qt

    Unless, of course, something reserves it via a #define.

    I prefer length_, since if you've got a spiffy type-ahead UI, you won't have everything starting with the same character.

  11. #11
    Join Date
    Jan 2006
    Posts
    31
    Thanked 5 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Is it possible to memory map a file in Qt

    I prefer _length to length_ because all the following sucks

    length_->something

    length_.something

    length_++

    length_[n]

    length_(x)

    x = length_;

    and probably also something more that I don't remember now.

  12. #12
    Join Date
    Jun 2012
    Posts
    173
    Thanks
    48
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Is it possible to memory map a file in Qt

    wysota
    can you please give exmple how to use the QwwMemoryMapper class you wrote in here

  13. #13
    Join Date
    Oct 2009
    Posts
    483
    Thanked 97 Times in 94 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Is it possible to memory map a file in Qt

    Quote Originally Posted by jesse_mark View Post
    wysota
    can you please give exmple how to use the QwwMemoryMapper class you wrote in here
    Seriously? You resurrect a 9-year old thread to ask for a tutorial for a 20-line wrapper around two functions? Besides memory-mapped files do exist under Windows and have been in Qt for a while now (see QFileDevice::map()).

  14. #14
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Is it possible to memory map a file in Qt

    Quote Originally Posted by jesse_mark View Post
    wysota
    can you please give exmple how to use the QwwMemoryMapper class you wrote in here
    Oh, come on...
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Draging a non-existing file to the Windows Desktop
    By klaus1111 in forum Qt Programming
    Replies: 13
    Last Post: 20th September 2007, 11:47
  2. How To Extract A File
    By deekayt in forum General Programming
    Replies: 7
    Last Post: 5th December 2006, 18:27
  3. .ui file name and classname
    By Rekha in forum Newbie
    Replies: 3
    Last Post: 12th August 2006, 01:53
  4. SQLite-DB in a qrc file
    By Lykurg in forum Qt Programming
    Replies: 5
    Last Post: 31st July 2006, 19:24
  5. dialog box
    By Bahar in forum Qt Programming
    Replies: 3
    Last Post: 31st January 2006, 14:52

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.