Results 1 to 4 of 4

Thread: the memory is not pure

  1. #1
    Join Date
    Jan 2006
    Posts
    976
    Qt products
    Qt3
    Platforms
    Windows
    Thanks
    53

    Default the memory is not pure

    Qt Code:
    1. memblock = new char [size];
    2. ifile.seekg (0, ios::beg);
    3. ifile.read (memblock, size);
    4. out.write (memblock, size);
    To copy to clipboard, switch view to plain text mode 
    Hi, when I write, file linked to out fstream, at the end, contain some caracters, that there aren't in the input file...... how avoid that caracters?
    thanks
    Regards

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    8
    Thanked 541 Times in 521 Posts

    Default Re: the memory is not pure

    That is probably because "size" is bigger than the actual file size...
    When you allocate memblock, it will contain some (rubbish) data(since you don't initialize it-e.g. memset, etc ).

    When you read from the input file, the first "size" bytes in memblock will be overwritten with data from the file, but the rest will remain.

    How do you compute "size" anyway?

    Regards

  3. #3
    Join Date
    Jan 2006
    Posts
    976
    Qt products
    Qt3
    Platforms
    Windows
    Thanks
    53

    Default Re: the memory is not pure

    Qt Code:
    1. int size;
    2. size = ifile.tellg();
    To copy to clipboard, switch view to plain text mode 
    Regards

  4. #4
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    8
    Thanked 541 Times in 521 Posts

    Default Re: the memory is not pure

    Querying the file pointer after you first open the file will return 0.

    Try this:
    Qt Code:
    1. ifile.seekg( -1, ios_base::end );
    To copy to clipboard, switch view to plain text mode 

    If this does not work, could you compare the size with the actual file size?

    Regards

Similar Threads

  1. Memory Leak in my Application :-(
    By Svaths in forum Qt Programming
    Replies: 4
    Last Post: 27th July 2007, 19:42
  2. How to measure memory of Qt Application,
    By rajeshs in forum Qt Programming
    Replies: 2
    Last Post: 10th July 2007, 17:03
  3. Memory Problem with SIGNALS and SLOTS
    By ^NyAw^ in forum Qt Programming
    Replies: 1
    Last Post: 19th March 2007, 20:39
  4. saving a c string of variable length in a shared memory?
    By nass in forum General Programming
    Replies: 4
    Last Post: 3rd January 2007, 14:40
  5. Qt 4.1 Memory Leak
    By blackliteon in forum Qt Programming
    Replies: 14
    Last Post: 10th February 2006, 12:47

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.