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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:57:33+00:00 2026-05-26T19:57:33+00:00

So i am making a custom edit control. In order to keep track of

  • 0

So i am making a custom edit control. In order to keep track of the contents of the edit control, I’m using a dynamically allocated char array.

  • Now, I know that I need to insert in the middle of the array in
    certain situations, such as when the user clicks on a particular
    point. So, I was thinking, instead of a character array, I may use
    std::vector, so i would be able to use the .insert function, and also
    wouldn’t have to care much about the memory management.
  • I was also thinking maybe to directly store the input stream into an
    array/vector of words(Without keeping a continuous buffer), since my
    whole purpose with this is to implement syntax highlighting.

Which would be a better approach to go about things? And why?

  • 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-26T19:57:34+00:00Added an answer on May 26, 2026 at 7:57 pm

    For a text buffer with today computers you can indeed just use a single contiguous buffer (e.g. a vector) because CPUs are fast enough to make insertion time (an o(n) operation with this naive approach) still a viable option.

    In the past when computers were thousands times slower a common simple approach was instead to keep the text in a buffer but with an “hole” corresponding to the cursor position, to make insertion an o(1) operation and moving chars from one side of the hole to the other when cursor was moving in the text (basically making cursor movement an o(k) operation where k is the number of skipped chars).

    For an editor designed for programmers the text is going to be subdivided in logical lines and therefore using an approach based on an array of pointers to lines seems appropriate. Even if this will make some cross-line operation somewhat annoying some of line-based operations will become easier… line numbering in display becomes a trivial problem, especially if you don’t need to implement line wrap (horrible with code anyway) by going for truncation and horizontal scrolling instead.

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

Sidebar

Related Questions

So, I'm making this text editor from scratch using a custom edit control. As
I'm making a custom control that can be dragged around and it is semi
I am making a custom control I need to add some default keybindings, microsoft
Does anybody know the logic behind making DataSourceSelectArguments sealed? I've implemented a custom DataSource
I am making a custom textbox control and am thinking about adding keybindings in
I'm making a custom page template in wordpress and adding an image by using
I'm in the process of making a custom control -- specifically a pie chart.
I am making a custom module which also enables an edit page to edit
I am making a custom ImageButton Control which has the option to show button
I have a custom control which is used on many pages. I am making

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.