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

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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T17:02:14+00:00 2026-06-10T17:02:14+00:00

Is there a way to find out how much memory is used by an

  • 0

Is there a way to find out how much memory is used by an instance of a class or basic data types in general?

I have a toy webframework in cl that creates and manages web pages with instances of classes that represent the html tags and their properties, and as they are supposed to make an html page, they have children in a slot called children. so I was thinking how much a user’s session will cost the server if I take this approach. Thanks.

  • 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-10T17:02:16+00:00Added an answer on June 10, 2026 at 5:02 pm

    As far as I know, there is nothing like this for arbitrary objects in the standard, but there are implementation-dependent solutions, like ccl:object-direct-size in CCL:

    CL-USER> (object-direct-size "foo")
    16
    

    However, be aware that whether these do what you want depends on what you mean by “size”, since those functions usually don’t include the size of the components the object references. You can also run the GC, initialize a few objects and compare room‘s output before and afterwards.

    Also, note that time usually includes allocation information:

    CL-USER> (time (length (make-array 100000)))
    (LENGTH (MAKE-ARRAY 100000))
    took 0 milliseconds (0.000 seconds) to run.
    During that period, and with 2 available CPU cores,
         0 milliseconds (0.000 seconds) were spent in user mode
         0 milliseconds (0.000 seconds) were spent in system mode
     400,040 bytes of memory allocated.
    100000
    

    Maybe you could try something like this (untested, really just a quick hack):

    (defmethod size ((object standard-object))
      (let ((size (ccl:object-direct-size object)))
        (dolist (slot (mapcar #'ccl:slot-definition-name
                              (ccl:class-slots (class-of object))))
          (when (slot-boundp object slot)
            (incf size (size (slot-value object slot)))))
        size))
    
    (defmethod size ((list list))
      (reduce (lambda (acc object) (+ acc (size object)))
              list
              :initial-value (ccl:object-direct-size list)))
    
    (defmethod size (object)
      (ccl:object-direct-size object))
    

    For example:

    CL-USER> (defclass foo ()
               ((child :accessor child :initarg :child)))
    #<STANDARD-CLASS FOO>
    CL-USER> (defclass bar (foo)
               ((child2 :accessor child2 :initarg :child2)))
    #<STANDARD-CLASS BAR>
    CL-USER> (size '())
    0
    CL-USER> (size "foo")
    16
    CL-USER> (size '("foo" "bar"))
    40
    CL-USER> (size (make-instance 'foo))
    16
    CL-USER> (size (make-instance 'foo :child '("foo" "bar" "baz")))
    72
    CL-USER> (size (make-instance
                    'bar
                    :child "foo"
                    :child2 (make-instance 'foo :child (make-array 100))))
    456
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any way to find out how much memory is available in iOS?
Is there a tool or a way to find out how much memory consumed
Is there a way to find out how much space (on disk) a row
I have been scouring the internet to find out how much memory a java
Is there a way or place to go to find out how much usage
Is there another way to find out the status of services on AppEngine other
Is there a way to find out which Javascript function is fired by click
Is there a way to find out programmatically what TestCategory is running in a
Is there any way to find out or store which app is accessing an
Is there a way to find out where a Python object was instantiated the

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.