Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 266777
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T23:28:20+00:00 2026-05-11T23:28:20+00:00

In short, I am wondering if there is an auto_ptr like type for arrays.

  • 0

In short, I am wondering if there is an auto_ptr like type for arrays. I know I could roll my own, I’m just making sure that there isn’t already something out there.

I know about vectors as well. however I don’t think I can use them. I am using several of the Windows APIs/SDKs such as the Windows Media SDK, Direct Show API which in order to get back some structures to call a function which takes a pointer and a size twice. The first time passing NULL as the pointer to get back the size of the structure that I have to allocated in order to receive the data I am looking for. For example:

CComQIPtr<IWMMediaProps> pProps(m_pStreamConfig);
DWORD cbType = 0;
WM_MEDIA_TYPE *pType = NULL;

hr = pProps->GetMediaType(NULL, &cbType);
CHECK_HR(hr);

pType = (WM_MEDIA_TYPE*)new BYTE[cbType];   // Would like to use auto_ptr instread
hr = pProps->GetMediaType(pType, &cbType);
CHECK_HR(hr);

// ... do some stuff

delete[] pType;

Since cbType typically comes back bigger than sizeof(WM_MEDIA_TYPE) due to the fact is has a pointer to another structure in it, I can’t just allocate WM_MEDIA_TYPE objects. Is there anything like this out there?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T23:28:20+00:00Added an answer on May 11, 2026 at 11:28 pm

    Use

    std::vector<BYTE> buffer(cbType);
    pType = (WM_MEDIA_TYPE*)&buffer[0];
    

    or since C++11

    std::vector<BYTE> buffer(cbType);
    pType = (WM_MEDIA_TYPE*)buffer.data();
    

    instead.


    Additional:
    If someone is asking if the Vectors are guaranteed to be contiguous the answer is Yes since C++ 03 standard. There is another thread that already discussed it.


    If C++11 is supported by your compiler, unique_ptr can be used for arrays.

    unique_ptr<BYTE[]> buffer(new BYTE[cbType]);
    pType = (WM_MEDIA_TYPE*)buffer.get();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just wondering If there is a quick code/ short cut to get all textbox,
I'm wondering if there's a short notation in PHP for getting an object field
I'm wondering if there are any good guides or books that explain the best
I know I can change File_init.txt 's definitions, but I was wondering if there
Im wondering if there is a short hand for collapsing a map of an
I am wondering if there is a short way (without programming the whole thing)
I'm using LINQ to SQL and I'm wondering if there is a short cut
so I was wondering if there is some trickery with slices that would allow
I would like to know how I can convert a short ASCII string to
I was wondering if there are any recommendations or features that one may remove/disable

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.