[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Memory allocation

Posted on 2006-05-25
4
Medium Priority
?
934 Views
Last Modified: 2008-01-09
What is the right way to use (and Why?)

wchar_t *ploc = NULL;
ploc=new wchar_t[4096];

1.       ploc = OLE2W( bsLocation);
Or.
2. wchar_t* ploc =  OLE2W( bsLocation);
or use wcsncpy?

or is there any better way....
0
Comment
Question by:pb_india
2 Comments
 
LVL 12

Accepted Solution

by:
rajeev_devin earned 100 total points
ID: 16766239
This is ok
wchar_t* ploc =  OLE2W( bsLocation);
0
 
LVL 11

Assisted Solution

by:Deepu Abraham
Deepu Abraham earned 100 total points
ID: 16766384
Hi pb_india,

You can see this link:
http://msdn2.microsoft.com/en-us/library/805c56f8.aspx

My answer would be, you can use all the points you have mentioned but that may depend on your program.

only caution in using OLE2W()/A2W() etc.. is you need to put this inside a function if it is getting called inside a loop.

wchar_t *ploc = NULL;

void foo()
{
    USES_CONVERSION;
     ploc=new wchar_t[4096];
     ploc = OLE2W( bsLocation);
}

Please refer to this site:USES_CONVERSION - a cautionary tale

http://untidy.net/blog/category/vc/

Also look for CA2WEX Class in MSDN.

Best Regards,
DeepuAbrahamK
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
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 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.
Suggested Courses

831 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