Memory allocation

Posted on 2006-05-25
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);
2. wchar_t* ploc =  OLE2W( bsLocation);
or use wcsncpy?

or is there any better way....
Question by:pb_india
    LVL 12

    Accepted Solution

    This is ok
    wchar_t* ploc =  OLE2W( bsLocation);
    LVL 11

    Assisted Solution

    Hi pb_india,

    You can see this link:

    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()
         ploc=new wchar_t[4096];
         ploc = OLE2W( bsLocation);

    Please refer to this site:USES_CONVERSION - a cautionary tale

    Also look for CA2WEX Class in MSDN.

    Best Regards,

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Join & Write a Comment

    This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
    Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
    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.

    728 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

    22 Experts available now in Live!

    Get 1:1 Help Now