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 532839
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T09:26:47+00:00 2026-05-13T09:26:47+00:00

Per-frame I need to allocate some data that needs to stick around until the

  • 0

Per-frame I need to allocate some data that needs to stick around until the end of the frame.

Currently, I’m allocating the data off a different memory pool that allows me to mark it with the frame count. At the end of the frame, I walk the memory pool and delete the memory that was allocated in a particular frame.

The problem I’m running into is that in order to keep a hold on the data, I have to place it in a structure thusly:

struct FrameMemory
{
    uint32 frameIndex;
    bool allocatedType; //0 = new(), 1 = new[]
    void* pMemPtr;
}

So later, when i get around to freeing the memory, it looks something like this:

{
for(all blocks)
 if(block[i].frameIndex == targetIndex)
     if(block[i].allocatedType == 0)
          delete block[i].pMemPtr;
     else if (block[i].allocatedType ==1)
          delete[] block[i].pMemPtr;
}

The issue is that, because I have to overload the pointer to the memory as a void*, the DELETE operator doesn’t properly DELETE the memory as its’ native base type. IE the destructor NEVER gets called for the object.

I’ve attempted to find ways to use smart-pointer templated objects for the solution, but in order to do that, I have to overload the templated class to a non-templated base-type, which makes deletion even more difficult.

Does anyone have a solution to a problem like this?

  • 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-13T09:26:48+00:00Added an answer on May 13, 2026 at 9:26 am

    If you don’t want to force all the objects to inherit from Destructible, you can store a pointer to a deleter function (or functor) along with the pointer to the data itself. The client code is responsible for providing a function that knows how to delete the data correctly, typically something like:

    void xxx_deleter(void *data) { 
        xxx *ptr = static_cast<xxx *>(data);
        delete ptr;
    }
    

    Though the deleter will usually be a lot like the above, this also gives the client the option of storing complex data structures and still getting them deleted correctly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I called this function once per frame and it took my FPS from >400
I am new in this field and i desperately need some guidance from u
I need to read fixed number of bytes from files, whose sizes are around
I am building an application that will do some object tracking from a video
Per man pages, snprintf is returning number of bytes written from glibc version 2.2
Per this helpful article I have confirmed I have a connection pool leak in
Per the Java documentation, the hash code for a String object is computed as:
Per version (1.0, 1.1, 2.0, 3.0, 3.5), how many classes are in the .NET
Per the example array at the very bottom, i want to be able to
As per my understanding stateless session beans are used to code the business logic.

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.