Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6929361
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:18:26+00:00 2026-05-27T11:18:26+00:00

I am working on a texture synthesis project. I am almost finished, however my

  • 0

I am working on a texture synthesis project. I am almost finished, however my process is taking ~2gb of memory while it is running. I thought I was freeing all of my calloc’ed arrays, but I could be wrong. C++ isn’t my specialty.

I know triple pointers were the wrong way to go about it in C++ but I am just more comfortable with them at the moment. Let me know if you need to see more code. Thank you.

MetaPic declaration

class MetaPic
{
    public:
        Pic* source;
        Pixel1*** meta;
        int x;
        int y;
        int z;
        MetaPic();
        MetaPic(Pic*);
        MetaPic(const MetaPic&);
        MetaPic(int, int, int);
        MetaPic& operator=(const MetaPic&);
        ~MetaPic();
        void allocateMetaPic();
        void copyPixelData();
        void copyToOutput(Pic*&);
        void copyToMetaOutput(MetaPic&, int, int);
        void copyToSample(MetaPic&, int, int);
        void freeMetaPic();

};

Allocating the triple pointer

    void MetaPic::allocateMetaPic()
{
    meta = (Pixel1***)calloc(x, sizeof(Pixel1**));

    for(int i = 0; i < x; i++)
    {
        meta[i] = (Pixel1**)calloc(y, sizeof(Pixel1*));
        for(int j = 0; j < y; j++)
        {
            meta[i][j] = (Pixel1*)calloc(z, sizeof(Pixel1));
        }
    }
}

Deallocating the triple pointer

void MetaPic::freeMetaPic()
{
    for(int j = 0; j < y; j++)
    {
        for(int i = 0; i < z; i++)
            free(meta[i][j]);
    }
    for(int i = 0; i < x; i++)
        free(meta[i]);

    free(meta);
}

Destructor

MetaPic::~MetaPic()
{
    freeMetaPic();
}

= Operator

MetaPic& MetaPic::operator=(const MetaPic& mp)
{
    freeMetaPic();

    source = mp.source;
    x = mp.x;
    y = mp.y;
    z = mp.z;
    allocateMetaPic();
    copyPixelData();

    return *this;
}

Copy constructor

MetaPic::MetaPic(const MetaPic& mp)
{
    source = mp.source;
    x = mp.x;
    y = mp.y;
    z = mp.z;
    allocateMetaPic();
    copyPixelData();
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T11:18:27+00:00Added an answer on May 27, 2026 at 11:18 am

    When freeing you seem to be using the wrong terminating values in your loops. Just make the freeMetaPic function undo what the allocate function does, ie:

    void MetaPic::freeMetaPic()
    {
        for (int i = 0; i < x; i++)
        {
            for (int j = 0; j < y; j++)
            {
                free(meta[i][j]);
            }
    
            free(meta[i])
        }
    
        free(meta);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a texture management and animation solution for a small side project
Is it possible to set different texture filtering when working with sprites?
Working on a project at the moment and we have to implement soft deletion
Working on a project that parses a log of events, and then updates a
Working in Eclipse on a Dynamic Web Project (using Tomcat (v5.5) as the app
Working through some OpenGL-ES tutorials, using the Android emulator. I've gotten up to texture
Scenario: I am working on a Android project where in one particular openGL page,
so i'm working with a bunch of 2048x2048 sprite sheets which fill up memory
I have a Texture2D readily available; I have an apparently-working shader texture sampler and
I've got PVR texture compression working all happy and good in my iPhone game,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.