answersLogoWhite

0

Exactly as you would any other type of array. An object's size is determined in the same way a structure's size is determined, by the sum total size of its member variables, plus any padding incurred by alignment.

However, you cannot create arrays of base classes. Arrays of objects can only be created when the class of object is final; a class that has a private default constructor, otherwise known as a "leaf" class. This is because derived classes can vary in size; array elements must all be the same size.

To create an array of base classes you must create an array of pointers to those base classes instead. Pointers are always the same size (4 bytes on a 32-bit system).

Static arrays are ideally suited to arrays of leaf objects where the number of objects never changes, or the maximum number of objects is finite and fixed. Although you can use dynamic arrays of leaf objects, you will incur a performance penalty every time the array needs to be resized, because every object's copy constructor must be called during the reallocation. Dynamic arrays are better suited to arrays of pointers to objects -- only the pointers need to be copied during resizing, not the objects they point to.

User Avatar

Wiki User

13y ago

What else can I help you with?

Related Questions

Why object array called universal array?

Object array is called universal array because it can store multiple variables of the same type


How delete an array of object within the object in C?

First locate the position of an array by search after than use a delete function to delete an array


How will you find the location of an element of an array?

Basically, &array[i]; That is, the memory location for an array object with index i. Or, you can do: (array + i);


How do you use character in c plus plus?

If you are referring to the character object 'char,' then here are a couple of uses:To create an object, use this:char object = 'a';To create an array of chars, use this:char array[10];To dynamically allocate an array of chars, use this:char array = new char[10];(Don't forget to delete the object with 'delete [] array')


What is the difference between array in c and c sharp language?

The syntax to access a particular element in an array are the same in both languages: For example: assume array is an array of 10 int(egers): to get the first element: array[0] (both are 0 based indexing] int i = 0; while (i < array.Length) { // do something to array[i] } int i = 0; int length = sizeof(array) / sizeof(int); while (i < length) { // do something to array[i] } However, an array in C# is also enumerable (C does not have this feature) in C#, you may loop thru the array by: foreach (int number in array) { // do something to array[i] } Plus, C# is an Object-Oriented Language, so that an array may be of some object types, not just those primitiives data types in C: object[] objectArray; // any object derived from Object may be placed into objectArray, not just struct. In another variation, an array may be of Delegate type in C#(sort of like function pointers in C)


Is string an object?

No. A string is, by definition, a character array.


Is string is an object?

No. A string is, by definition, a character array.


What is javascript array object?

An object in JavaScript is anything that holds information. Arrays, strings, numbers and booleans are all objects. You can then use methods and functions to manipulate those objects. If you want to know more about objects, see the related links.


Can object have array of characters?

If by an object you mean a class or a struct, yes they can. Define the char array like you normally would but don't intialize any data into it. Do this in the constructor


A part of an object that you hold?

Handle


Why might one need a sting array object in Java?

One might need a sting array object in Java to use protective measures on one's computer to prevent one's program from writing outside the bounds of the array.


Can Array List in java hold different data types?

No, we cant hold different data types in an Array. But using Array List we can hold any data type as a Object. But you need iterate that values as a Object and again you need to convert those values into the different data types accordingly.