Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

heap->stack

Posted on 2004-10-31
2
Medium Priority
?
306 Views
Last Modified: 2010-04-01
Hi,
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.

0
Comment
Question by:pisselou
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 22

Accepted Solution

by:
grg99 earned 200 total points
ID: 12456681
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?



0
 

Author Comment

by:pisselou
ID: 12456759
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.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
Suggested Courses

618 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