Posted on 2004-10-31
Last Modified: 2010-04-01
How should you change this heap-allocation-code to stack-allocation-code ??
      textel->length = 15* sizeof(int16);
      textel->buffer = new int16[textel->length];
Thanks in advance.

Question by:pisselou
    LVL 22

    Accepted Solution

    about the closest you can get is to define:

    int16 buffer[15];

    as part of the struct.  But it's still probably heap-based, as the struct seems to be accessed by a pointer, most likely created thru a malloc(), although it could be a pointer to static or stack struct too.

    Perhaps we coul dhelp more if you'd tell us exactl;y what you're trying to do, and why, and where textel comes from, and is textel static or dynamically allocated, one or multiple times?


    Author Comment

    Hi, I got code which worked, but when I looked with the task manager I clearly had a memory leak (memory raised till it crashed). Now it works fine, and
    1) without memory leak
    2) I don't have to think about placing the delete
    3)maybe faster, since it's on the stack

    So, thanks a lot.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Article by: SunnyDark
    This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
    Some Windows API functions expect you to provide a pointer to a CALLBACK function that the system will need to call as part of the operation.  Such API functions as SetTimer, timeSetEvent, CreateThread, EnumWindows, LineDDA, even window message hand…
    The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
    The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

    846 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    9 Experts available now in Live!

    Get 1:1 Help Now