Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. IT & Infrastructure
  4. Objects functions memory consumption

Objects functions memory consumption

Scheduled Pinned Locked Moved IT & Infrastructure
questionperformancehelp
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MikeMarq
    wrote on last edited by
    #1

    I am writing a program with alot of data structures and using objects for this purpose. For some of these data structures I am using a huge number of objects so I don't want to waste memory unnecisarily with each object. Here's my question, does it make any difference in terms of memory consumption if I put some of the functions for manipulating these objects inside the class for that object or in a seperate class or module that I only make only one copy of? In other words does each copy of an object have a reference to its functions or does the compiler seperate them internally. thanks for your help

    M 1 Reply Last reply
    0
    • M MikeMarq

      I am writing a program with alot of data structures and using objects for this purpose. For some of these data structures I am using a huge number of objects so I don't want to waste memory unnecisarily with each object. Here's my question, does it make any difference in terms of memory consumption if I put some of the functions for manipulating these objects inside the class for that object or in a seperate class or module that I only make only one copy of? In other words does each copy of an object have a reference to its functions or does the compiler seperate them internally. thanks for your help

      M Offline
      M Offline
      Mark Salsbery
      wrote on last edited by
      #2

      MikeMarq wrote:

      does it make any difference in terms of memory consumption if I put some of the functions for manipulating these objects inside the class for that object or in a seperate class or module that I only make only one copy of?

      No. Encapsulating code in the class is beneficial for design, however, and is one of the key benefits of object-oriented programming.

      MikeMarq wrote:

      In other words does each copy of an object have a reference to its functions or does the compiler seperate them internally.

      I know C++ and C#, and for those languages: All instances of a class/struct are "object"s Only one copy of the code exists, whether it's class/struct method code or code outside of a class/struct. For code "inside the class", an implicit "this" pointer, which is a pointer/reference to the object the code is being called on, so the code runs in the context of that object (meaning only one copy of the code is needed). An object doesn't need a reference to its code...it IS the reference. Mark

      Mark Salsbery Microsoft MVP - Visual C++ :java:

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups