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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T22:44:53+00:00 2026-05-24T22:44:53+00:00

In the obj-c, we can create vector objects as follows: SomeClass* example[100]; or int

  • 0

In the obj-c, we can create vector objects as follows:

SomeClass* example[100];

or

int count[7000];

But what if we know the size of the vector only at the time init the class?
(Maybe we need example[756] or count[15])

  • 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-24T22:44:54+00:00Added an answer on May 24, 2026 at 10:44 pm

    First of all, those aren’t vector objects, they’re compile-time arrays. One of the features of compile time arrays is automatic memory management; that is, you don’t have to worry about allocation and deallocation of these arrays.

    If you want to create an array whose size you don’t know until runtime, you’ll need to use new[] and delete[]:

    int size = somenumber;
    int* arr = new int[size];
    
    // use arr
    arr[0] = 4;
    
    // print the first value of arr which is 4
    cout << arr[0];
    

    The catch is that after you’re done with this array, you have to deallocate it:

    delete[] arr;
    

    If you forget to deallocate something created by new with a corresponding delete1, you’ll create a memory leak.

    You are probably better off using std::vector though because it manages memory for you automatically:

    // include the header
    #include <vector>
    
    using namespace std; // so we don't have std:: everywhere
    
    vector<int> vec; // create a vector for ints
    vec.push_back(4); // add some data
    vec.push_back(5);
    vec.push_back(6);
    
    // vec now holds 4, 5, and 6
    
    cout << vec[0]; // print the first element of vec which is 4
    
    // we can add as many elements to vec as we want without having to use any
    // deallocation functions on it like delete[] or anything
    // when vec goes out of scope, it will clean up after itself and you won't have any leaks
    

    1 Make sure you use delete on pointers that you created with new and delete[] on pointers you make with new[x]. Do not mix and match them. Again, if you use std::vector, you don’t have to worry about this.

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

Sidebar

Related Questions

I know you can create literal objects with subobjects and functions: var obj =
Hey all. I know this sounds simple, but I can't find a way to
How can I create a function that can't be called from outside? var obj
We normally create objects using the new keyword, like: Object obj = new Object();
I'm trying to create a generic method to cast an object, but can't seem
In c# i can create functions can return any type of objects like (ArrayList)
Example: Class *_obj1; Class *_obj2; void doThis(Class *obj) {} void create() { Class *obj1
How can I create a webserver from my Obj-C app, and post custom HTML
How can i find out if the obj returned by a func is a
How can I unzip a file in MacOS X Obj-C? What frameworks do I

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.