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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T22:09:02+00:00 2026-06-09T22:09:02+00:00

I am trying to make a simple object pool and i cant get it

  • 0

I am trying to make a simple object pool and i cant get it to work .
My code crashes when using malloc to allocate space for a dynamic array of template’s type

my code:

template <class cl>
class ObjectPool{
public:
    gltAtlasRenderer* br;
    cl* items;
    int SIZE,texid;

    void Innit(int size,int texidi)
    {
        SIZE=size;
        items=(cl*)malloc(sizeof(cl)*SIZE);->>>>>>>>>>HERE MY APP CRASHES
        /*br=new gltAtlasRenderer(SIZE,false,1);
        texid=texidi;
        for(int c=0;c<SIZE;c++)items[c].alive=false;
        */
    }
    void Update(Arena*  arena)
    {
        for(int c=0;c<SIZE;c++)
        {
            if(!items[c].alive)continue;
            items[c].Update(arena);
        }
    }
    void Render()
    {
        br->RenderStart();
        for(int c=0;c<SIZE;c++)
        {
            if(!items[c].alive)continue;
            items[c].Render(br);
        }
        br->RenderStop(texid);
    }
};

All the examples that i found in the web are using fixed arrays and vectors ,but i need the array to be allocated at runtime.

EDIT:
This is how i create it:

ObjectPool<Enemie1>* enemies1;
void Innit()
{
         enemies1->Innit(size,texid);
}

I know that is crashing in that line cause if i commend it it doesnt crashes

  • 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-06-09T22:09:03+00:00Added an answer on June 9, 2026 at 10:09 pm

    This will not work:

    ObjectPool<Enemie1>* enemies1;
    void Innit()
    {
             enemies1->Innit(size,texid);
    }
    

    You need to allocate the memory before using it, like this:

    ObjectPool<Enemie1>* enemies1;
    void Innit()
    {
             enemies1 = new ObjectPool<Enemie1>;
             enemies1->Innit(size,texid);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to make a very simple object rotate around a fixed point
I'm trying to make simple script using jquery $post function to pass data to
I am trying to make a simple application using Google App Engine. Below is
Im trying to make a simple downloader, but i cant make it to update
I'm trying to make a simple stopwatch but it just doesn't work.. The app
I am trying to make a simple web application using ASP.NET and Interop COM.
I'm trying to make a simple windows 8 metro game using c# and xaml.
Background: Trying to make a simple drop the ball game. The code is located
I'm trying to make a simple multiplayer game using canvas, socket.io and node.js. Everything's
I'm trying to make a simple image browser for TinyMCE which I am using

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.