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

  • Home
  • SEARCH
  • 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 8930335
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:52:18+00:00 2026-06-15T08:52:18+00:00

This is more of a general question, but I don’t know if the space

  • 0

This is more of a general question, but I don’t know if the space differs for different programming languages, so I tagged it with actionscript-3. I’ve had a lot of instances where I need a vector of usually 1 element, but maybe more some times. For example, how much more memory would I save if I use an int versus a vector of 1 int? Let’s say that I have a function that does something to all numbers in a vector. The input is usually going to be a single int, but some times I might need more. The size of the vector is also fixed, so I have no chance of a 1 element vector turning into a 2 element one.

Now I could do 2 things:

1) I could only use Vectors and have one function that takes in a vector, or

2) I could define 1 function that takes in a single int and another function that does the same thing but takes in a Vector of int’s.

Or maybe I could have it take in any type of argument, check the type of input and then cast it to an integer or vector? Basically, should I make 2 functions that caters to both cases or just 1 that only uses a vector?

  • 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-15T08:52:19+00:00Added an answer on June 15, 2026 at 8:52 am

    OK took out the old example since it didn’t really apply.

    If the size of the vector is not specified ahead of time, the size increases when the vector runs out of space. Each time the size of the vector increases, a new block of memory is allocated. So by not predefining the size of your vector, the memory footprint is just what’s needed to store one int.

    So making one class is not a bad idea based on that alone. But now you need to look at the OOP of it all. So if most of your locks have one key, you really don’t what to have to access lock.keys[0] most of the time especially to even know you need to do that, you still need some indicator that it only needs and needs and has one key. lock.lockType or lock.requiredNumKeys or both. Since all of this logic and properties are specific to the rare times you need multiple keys, I say…

    Build 2 classes.

    EDIT:

    One thing I thought I would mention is in using two classes you will probably at some point want an Array or Collection of locks. Make both classes implement and interface like IKeyedLock which defines a function addKey() and maybe a get isLocked() this way you can have a list will all IKeyedLocks, but the SingleKeyLock and MultiKeyLock classes determine differently if they are still locked or not and how to add a key (or keys)

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

Sidebar

Related Questions

I know this SO question, but it deals with the subject in more general
This is more a general question but my particular case involves a ruby/rails app
I have a Yesod application (but question is more general than this) that allows
Although I tagged this question as a Morphia issue, I think it's more general,
This is a more general question, but which has wider implications for a data
So this is more of a general question about apps and techniques rather than
This is more of a general design question I guess... I have an Ajax
this may be a more general opengl question. using OpenGL ES for 2d, and
I suppose this question is more general than working with COM components. I have
This is less an HTML, CANVAS question and more of a general math question.

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.