Solved

Memory implications and runtime behaviour

Posted on 2002-03-29
5
171 Views
Last Modified: 2010-04-02
const char* strName="";
strName=getstr(var);
Func(strName);


const char* strName="none";
strName=getstr(var);
Func(strName);

What are the implications of this code w.r.t memory and runtime behaviour

Getting a runtime assertion.
Could this part be responsible?

Better way of doing it.
NOTE: Func cannot take a typecasted const char* as input.
0
Comment
Question by:bitnal
  • 3
5 Comments
 
LVL 30

Accepted Solution

by:
Axter earned 50 total points
ID: 6905818
If you which to modify the data that is being pointed to by strName, then try the following instead;

char strName[] = "none";


0
 

Author Comment

by:bitnal
ID: 6905931
Wont that create a problem in calling the function func().
This is a 3-party function and I cannot change it.
secondly, Will this format not require any allocation and freeing of memory?

thanks.
0
 
LVL 30

Expert Comment

by:Axter
ID: 6905968
>>Wont that create a problem in calling the function func().
What type does the Func take?

>>secondly, Will this format not require any allocation >>and freeing of memory?
No.
0
 
LVL 30

Expert Comment

by:Axter
ID: 6905978
The code you posted is a little confusing.

What is "var"?  What type is it, and where is it coming from?

If var is a non-const variable, then you can change your code to the following:

char* strName=getstr(var);
Func(strName);


With out seeing the rest of your code, it's hard to tell what you really need.

Please post more code.
0
 
LVL 11

Expert Comment

by:griessh
ID: 6956305
Dear bitnal

I think you forgot this question. I will ask Community Support to close it unless you finalize it within 7 days. You can always request to keep this question open. But remember, experts can only help you if you provide feedback to their questions.
Unless there is objection or further activity,  I will suggest to accept

     "Axter"

comment(s) as an answer.

If you think your question was not answered at all, you can post a request in Community support (please include this link) to refund your points. The link to the Community Support area is: http://www.experts-exchange.com/commspt/

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
======
Werner
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

705 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

18 Experts available now in Live!

Get 1:1 Help Now