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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T13:25:27+00:00 2026-06-09T13:25:27+00:00

I have some data type which, if I were to use plain old C

  • 0

I have some data type which, if I were to use plain old C, would be implemented as

typedef struct {
    ...many other members here...
    unsigned short _size;
    char           _buf[0];
} my_data; 

What I’d like to do, is to basically make that a class and add the usual operators like less, equality, copy constructor, operator assignment, and so on. As you can imagine I would then be using such class in associative containers like std::map as its key.

I need the buffer to be ideally at the same level of the object itself, otherwise when I have to compare two of them (buffers) I would have the CPU to take the pointer and load it in memory; I don’t want to use std::vector because memory allocated wouldn’t be contiguous with the rest of the data members.

Main issue for me is the fact that in C I would have a function which, given the size of the buffer would allocate proper memory size for it. In C++ such thing can’t be done.

Am I right?
Cheers

  • 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-06-09T13:25:28+00:00Added an answer on June 9, 2026 at 1:25 pm

    This is quite impossible. Your object is effectively of variable size but the std::map will always treat it as a fixed size, and there is no way to implement copying or moving. You would need an old C-style container to use such a hack.

    Edit: Custom allocator. Interesting solution, I hadn’t thought of that. I don’t know if you could make it work but it would be worth looking into.

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

Sidebar

Related Questions

I have some prices in my DB which are stored as data type money
Have some data in a sybase image type column that I want to use
I'd like to read some data which itself specifies the data type to use.
I have grabbed some XML data using this piece of jQuery: $.ajax({ type: POST,
I have defined a table type PL/SQL variable and added some data there. create
I have some data from log files and would like to group entries by
I have some data which (quite reasonably) uses null and false for different meanings.
I have some data files from a legacy system that I would like to
I have a class called Textures that use holds some data like this //Textures.h
I have a thread which produces some data (a python list) and which shall

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.