Memory allocated by user defined data structures in C/C++

Revision en1, by BumbleBee, 2018-01-01 08:48:03

Somwtimes we use different user deffined data structures in C/C++. For example,

struct data1{
    string name;
    int id;
    double marks;
}

We can also use operator overloading and user defined functions in structers.

struct data2{
    string name;
    int id;
    double marks;
    
    bool operator < (const data &a) const{
        return id<a.id;
    }

    void addMarks(double x)
    {
        marks+=x;
    }
}

Using operator overloading or user defined functions makes the use of these structures easy.

Now my question is, when I declare an array or vector of a structure, will it allocate more memory if the structure contains some user defined functions in it?

For example, if I declare two vectors of the structures declared above ( data1 and data2 ) like given below, will they allocate same amount of memory?

vector <data1> v1(1000);
vector <data2> v2(1000);

Is the amount of memory allocated increases if the structures contains some functions in it?

Tags #c, #c++, #data structure

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English BumbleBee 2018-01-01 08:48:03 1116 Initial revision (published)