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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T08:06:03+00:00 2026-05-16T08:06:03+00:00

So I want to have a buffer with an array of structs like this:

  • 0

So I want to have a buffer with an array of structs like this:

EventItem
{
   tag; // some string or array of characters to describe the value;
   value; // some integer or something

}

The value can be anything like int32. What I am concerned about is the tag. If I have an array of these objects, and I make the tag a string, what happens if the user inputs an EventItem into this buffer that has a long tag? Will that cause the buffer or parts of it to be copied to somewhere else in memory to hold this bigger EventItem (bigger because of this long string)?

Would it be better for me to limit the tag by just using a fixed amount of character by using an array instead of a string?

Obviously I don’t know exactly what I’m talking about, but I don’t know how the buffer can be created with the right amount of contiguous space without knowing the size of the EventItems in advance.

Could someone explain how this situation would go down for me?

Thanks very much in advance!

  • 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-16T08:06:04+00:00Added an answer on May 16, 2026 at 8:06 am

    What you want is a std::string.

    Not only because its c++ and not c, but also because operating on std::strings is much easier than on char[].

    Also, the construction of your struct might be easier and more straightforward as well, avoiding copy of char[]

    struct EventItem{
    
       EventItem(const int_32 value,const std::string&tag):m_value(value),m_tag(tag){}
    
       int_32 m_value;
       std::string m_tag;
    };
    

    What I am concerned about is the tag.
    If I have an array of these objects,
    and I make the tag a string, what
    happens if the user inputs an
    EventItem into this buffer that has a
    long tag? Will that cause the buffer
    or parts of it to be copied to
    somewhere else in memory to hold this
    bigger EventItem (bigger because of
    this long string)?

    Not clear (IMO), but im leaned towards the “no, and dont worry about it”. The only way that could happen would be that the buffer crosses a page boundary (assuming paged memory here). Well, if it happens, it happens. The miracle of virtual memory will take care of it.

    Obviously I don’t know exactly what
    I’m talking about, but I don’t know
    how the buffer can be created with the
    right amount of contiguous space
    without knowing the size of the
    EventItems in advance.

    Let std::vector take care of that. Of course, situations may arise always where contiguous space may not be available. Why are you so worried. Can you explain to us the situation where this would be a problem?

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

Sidebar

Related Questions

I want my emacs buffer to have a different name than the file name.
I want to double buffer a custom control which contains buttons. I have tried
I want to have a PHP script send a XML formatted string to another
I want to have a select-only ComboBox that provides a list of items for
I want to have a text box that the user can type in that
I want to have a class which implements an interface, which specifies the specific
I want to have a web based admin to upload, delete files and folders
I want to have two items on the same line using float: left for
I want to have the context menu of links provide me an option to
I want to have a function that will return the reverse of a list

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.