Results 1 to 4 of 4

Thread: Puzzled about how QString allocates memory

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Nov 2009
    Location
    Laval, France
    Posts
    124
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Puzzled about how QString allocates memory

    Hello all,
    I'm using some C functions that expect old fashionned ascii string paths, but I'm using Qt utilities to handle the paths.
    Here is a sample static method I wrote:
    Qt Code:
    1. char *PathUtil::toWinAscii(QString fullpath)
    2. {
    3. QByteArray ba = fullpath.toLocal8Bit();
    4. char *s = ba.data();
    5. #if WIN32
    6. char *p = s;
    7. while(*p){if(*p == '/')*p = '\\'; p++;}// convert Qt's separators to Windows compatible separators
    8. #endif
    9. return s;
    10. }
    To copy to clipboard, switch view to plain text mode 

    Now if I do thousands of calls of this function (because I'm dealing with thousands of files), I expect to get a lot of memory eaten up.
    Should I free the memory allocated by data() with free or delete []?
    My guess is that I should get into the sources, but I still wonder whether this is discussed in the documentation.

    UPDATE:
    Sorry, but I am not sure if it really works at all. Is the value being returned treated as an "automatic variable", and disappear on return from the method?
    Last edited by feraudyh; 28th December 2013 at 18:53.

Similar Threads

  1. Qt 4.6.3 QString and memory consumption
    By webquinty in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 10th April 2012, 15:45
  2. QString memory consumption
    By sicker in forum Newbie
    Replies: 1
    Last Post: 4th November 2011, 16:23
  3. Replies: 2
    Last Post: 11th August 2011, 15:42
  4. Replies: 4
    Last Post: 31st January 2008, 20:44
  5. QString memory usage
    By jogeshwarakundi in forum Newbie
    Replies: 1
    Last Post: 13th December 2007, 06:48

Tags for this Thread

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.