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 6590157
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:15:54+00:00 2026-05-25T17:15:54+00:00

This is very similar to this question , but the answers don’t really answer

  • 0

This is very similar to this question, but the answers don’t really answer this, so I thought I’d ask again:

Sometimes I interact with functions that return variable-length structures; for example, FSCTL_GET_RETRIEVAL_POINTERS in Windows returns a variably-sized RETRIEVAL_POINTERS_BUFFER structure.

Using malloc/free is discouraged in C++, and so I was wondering:
What is the “proper” way to allocate variable-length buffers in standard C++ (i.e. no Boost, etc.)?

vector<char> is type-unsafe (and doesn’t guarantee anything about alignment, if I understand correctly), new doesn’t work with custom-sized allocations, and I can’t think of a good substitute. Any ideas?

  • 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-25T17:15:54+00:00Added an answer on May 25, 2026 at 5:15 pm

    If you like malloc()/free(), you can use

    RETRIEVAL_POINTERS_BUFFER* ptr=new char [...appropriate size...];
    
    ... do stuff ...
    
    delete[] ptr;
    

    Quotation from the standard regarding alignment (expr.new/10):

    For arrays of char and unsigned char, the difference between the
    result of the new-expression and the address returned by the
    allocation function shall be an integral multiple of the strictest
    fundamental alignment requirement (3.11) of any object type whose size
    is no greater than the size of the array being created. [ Note:
    Because allocation functions are assumed to return pointers to storage
    that is appropriately aligned for objects of any type with fundamental
    alignment, this constraint on array allocation overhead permits the
    common idiom of allocating character arrays into which objects of
    other types will later be placed. — end note ]

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So, this question is similar to what I need, but the answers there don't
This is similar to a previous question , but the answers there don't satisfy
There is a similar question to this but answer is very general, vague.( Detecting
My question popped up a very similar question, this one . But the accepted
I know there is this question that is very similar, but I wanted to
This question can be very simple but could not find the answer; I receive
I've run across two very similar questions but the answers there apparently don't apply
I know this is very similar to a few other questions, but I can't
This is a very similar question to this SO thread on middleware and views
This is very similar to another recent question: How can I return the current

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.