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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T02:17:16+00:00 2026-05-11T02:17:16+00:00

Is there a way to get the actual size of a class instance in

  • 0

Is there a way to get the actual size of a class instance in Delphi?

I know about the InstanceSize method of the TObject class but that method does not recursively invokes itself for object members. For example, let’s say we have two classes:

type MyClass1 = class   private     myVar1 : integer;     myVar2 : integer; end;  type MyClass2 = class   private     myOtherVar1 : integer;     myOtherVar2 : MyClass1; end; 

for this segment of code, MyClass1 will be 12 bytes length (4 bytes for each integer plus 4 for the class overhead) and MyClass2 will be 24 bytes lengh (4 bytes for the class overhead, 12 bytes from myOtherVar2 and another 4 for the myOtherVar1 integer). Using InstanceSize will result on 12 bytes for each of them since myOtherVar2 is interpreted as a pointer (4 bytes) instead of as a class reference.

Is there a way to get the total size of the class including its reference to other class instances?

  • 1 1 Answer
  • 2 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. 2026-05-11T02:17:16+00:00Added an answer on May 11, 2026 at 2:17 am

    Construct one MyClass1 object and a million MyClass2 such that each MyClass2 points to the same MyClass1.

    How much memory does each MyClass2 take? 12.000012 bytes?

    How much memory does a circular list take? Infinity as you can keep chasing pointers for ever?

    In languages with pointers, a naive recursive size-of algorithm isn’t useful in general. You need to write your own algorithm which embodies knowledge about the aggregation/composition, sharing and recursive references specific to how you’re using the objects.

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

Sidebar

Ask A Question

Stats

  • Questions 65k
  • Answers 65k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer After further investigation, it appears that when any part of… May 11, 2026 at 11:19 am
  • added an answer How is copying an assembly to another machine and loading… May 11, 2026 at 11:19 am
  • added an answer The types in an Object[] will never really be primitive… May 11, 2026 at 11:19 am

Related Questions

Is there a way to get the actual size of a class instance in
Is there a way to get the tests inside of a TestCase to run
Is there a way to get the current xml data when we make our
Is there a way to get the C/C++ preprocessor or a template or such
Is there a way to get the raw SQL string executed when calling PDOStatement::execute()
Is there a way to get the SearchPath API to not search in c:\windows
Is there a way to get the Unicode Block of a character in python?
Is there a way to get the directory of a project in Eclipse? We
Is there a way to get the count of rows in all tables in
Is there a way to get the path for the assembly in which the

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.