×

Discussion Board

Results 1 to 8 of 8
  1. #1
    Regular Contributor
    Join Date
    Apr 2007
    Location
    Philippines
    Posts
    60

    Exclamation Memory management

    Good day! I would like to know how to clean up a complex allocation such as an array of arrays if you don't want to push it in the cleanup stack. My program always has leaks when closed.

    e.g. TReal32* *something = (TReal32**) User::AllocL(number1*sizeof(TReal32));
    and then
    for (i = 0; i < number; i++)
    something[i] = (TReal32*) User::AllocL(number2*sizeof(TReal32));


    I know that for an array, we use delete []array_name; right? Please help. Thanks.

  2. #2
    Regular Contributor
    Join Date
    May 2007
    Posts
    463

    Re: Memory management

    Yes, but that's not an array, it's a **.

    You're leaking the memory that the inner pointers point to. You have to delete the inner pointers first:

    Code:
    while (--number >= 0)
        delete something[number];
    
    delete something;
    Also, when you find yourself building complex datatypes like this, that's a pretty good indication you ought to be defining a class (C++) or a struct (C). Semantically, these sorts of structures don't mean anything, and make your code hard to maintain and debug.
    Get Resolvr - The Zeroconf framework for Symbian OS free today. Make your IP networking applications fun and easy to use. http://www.novelinteractions.com/resolvr/
    Proud to be the only autorickshaw owner in Cambridge - http://blog.novelinteractions.com/images/tuktuk.jpg

  3. #3
    Regular Contributor
    Join Date
    Apr 2007
    Location
    Philippines
    Posts
    60

    Exclamation Re: Memory management

    Thank you for the fast reply! But what if this array of arrays is a data member of a class and that the allocation is dynamic? How am I going to tell the destructor about the size of the allocation that transpired in a specific run?

  4. #4
    Regular Contributor
    Join Date
    May 2007
    Posts
    463

    Re: Memory management

    Well, like I said, don't.

    An array of arrays isn't something you ought to be declaring on a regular basis. What you really want is a class that includes an array of classes as a data member.
    Get Resolvr - The Zeroconf framework for Symbian OS free today. Make your IP networking applications fun and easy to use. http://www.novelinteractions.com/resolvr/
    Proud to be the only autorickshaw owner in Cambridge - http://blog.novelinteractions.com/images/tuktuk.jpg

  5. #5
    Regular Contributor
    Join Date
    Apr 2007
    Location
    Philippines
    Posts
    60

    Exclamation Re: Memory management

    Oh i see.

    What you really want is a class that includes an array of classes as a data member.

    Please correct me on this. The class (in red) you're talking about would be the one containing the subset array, am I right? (i.e. the column index of the resulting matrix)

    Thanks in advance!

  6. #6
    Regular Contributor
    Join Date
    May 2007
    Posts
    463

    Re: Memory management

    I could give you better advice if you actually said what you are trying to represent, rather than an abstract case.
    Get Resolvr - The Zeroconf framework for Symbian OS free today. Make your IP networking applications fun and easy to use. http://www.novelinteractions.com/resolvr/
    Proud to be the only autorickshaw owner in Cambridge - http://blog.novelinteractions.com/images/tuktuk.jpg

  7. #7
    Regular Contributor
    Join Date
    Apr 2007
    Location
    Philippines
    Posts
    60

    Lightbulb Re: Memory management

    Well, I'm implementing a local speech recognition system for the Filipino language targetting N95. I have a localized recorder that works fine without any leaks, and three other modules that do the processing. The modules for this system requires lots of mathematical processes. Fortunately, so far, my program compiles and can run all the modules but I can't solve the memory leaks coming from all those, as I've said, array of arrays I've been allocating when I exit the application. The array of arrays ideally represents matrix of floats that I manipulate from the time I allocate them until the end of a particular module. I am using RunL from CActive to run the long processes using switch so I have to make those array of arrays a data member of the module's class to pass it from one process to another. I don't know what's the best information to give, sorry.

  8. #8
    Regular Contributor
    Join Date
    May 2007
    Posts
    463

    Re: Memory management

    So, it's a representation of a matrix?

    Personally, I'd use a flat block of memory to represent that. I'd have a class CMatrix that has a data member TFloat[] iBuf = new TFloat[width * height]. Record the width and height in other data members.

    The advantage of having a flat structure like this is that now row ops are blazingly fast, since they all use sequential memory access. Depending on the machine, you can even drop to the assembly level and start using SIMD instructions to accelerate row ops.

    To be honest, I reckon you're going to need every ounce of speed you can get. Have you tried this on real hardware yet? If you're using floating point everywhere, it's going to be horrendously slow...
    Get Resolvr - The Zeroconf framework for Symbian OS free today. Make your IP networking applications fun and easy to use. http://www.novelinteractions.com/resolvr/
    Proud to be the only autorickshaw owner in Cambridge - http://blog.novelinteractions.com/images/tuktuk.jpg

Similar Threads

  1. CAknForm/CAknDialog and memory management
    By ValentinK in forum Symbian
    Replies: 0
    Last Post: 2006-07-10, 20:16
  2. RVCT vs. GCCE memory management
    By damsku in forum Symbian
    Replies: 0
    Last Post: 2006-07-06, 07:33
  3. Memory management for the Nokia 5140 (Flash organisation)
    By digitalmatter in forum General Development Questions
    Replies: 0
    Last Post: 2005-07-28, 11:45
  4. memory / file management
    By victorh81 in forum Symbian
    Replies: 3
    Last Post: 2004-04-28, 20:29
  5. can not successfully link any sample using .NET
    By lobotomat in forum Symbian Tools & SDKs
    Replies: 2
    Last Post: 2002-08-20, 00:29

Posting Permissions

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