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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T00:02:36+00:00 2026-05-23T00:02:36+00:00

I’m not too sure how to ask this question. I need to store a

  • 0

I’m not too sure how to ask this question. I need to store a ton of data into a vector at the beginning of the program, but only once. I tried putting that vector, my_vect, inside a constructor in a base class to load all the data into it, but the problem is, that data needs to be used by the derived classes that will be created throughout the program.

Essentially (unless I took a totally different approach?) the vector needs to be static because I don’t want to have to reload the data into the vector every time a child class is created. Can I somehow create this my_vect globally to avoid this static singleton stuff? I also need to be able to iterate through my_vect extremely fast in my derived classes. Is putting extern in every file a good choice? Please forgive me for any convoluted-ness, and say if you need any clarification.

EDIT:

Heres the jist of my program. I have a vector that reads thousands of lines from text file and stores them by words. No prob. I need to do that at the start of my program and I only want to store them once. After they are stored, every class I have needs to have fast my_vect[incr] access to the vector. I tried putting that vector as protected inside a base class so its initialized from the start, but the problem was that every time a new derived class object is created it would be loading all the data into the vector again. I only want the vector to be stored once, and used everywhere. Maybe singletons arn’t the way to go?

  • 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-23T00:02:37+00:00Added an answer on May 23, 2026 at 12:02 am

    Why do you need to inherit from the singleton to use the data it provides? You can make a singleton as the data provider, and make the other classes use it to access the data.

    In fact, you don’t even need a singleton. Just make an ordinary class with a static field and a static method to initialize the field. Then call the static method from main() before any of the threads are started to simplify the code. For the rest, since the class has no data, you can instantiate it at a tiny cost, and use it as you would any other class.

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

Sidebar

Related Questions

I have some data like this: 1 2 3 4 5 9 2 6
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on
For some reason, after submitting a string like this Jack’s Spindle from a text
I'm looking for suggestions for debugging... If you view this site in Firefox or
I am currently running into a problem where an element is coming back from
I have a JSP page retrieving data and when single or double quotes are
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I need to clean up various Word 'smart' characters in user input, including but
I want use html5's new tag to play a wav file (currently only supported

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.