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. General Programming
  3. C#
  4. Basic question about memory allocation

Basic question about memory allocation

Scheduled Pinned Locked Moved C#
csharpquestionperformancetutorial
5 Posts 3 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.
  • A Offline
    A Offline
    A M SOMAN
    wrote on last edited by
    #1

    I have a very basic question. If I declare some variables in my class and just run my C#.Net program, without any work done in it, will it allocate a memory for these variables? For Example, Class abc { public int a; public double b; } Regards, Anil

    B 1 Reply Last reply
    0
    • A A M SOMAN

      I have a very basic question. If I declare some variables in my class and just run my C#.Net program, without any work done in it, will it allocate a memory for these variables? For Example, Class abc { public int a; public double b; } Regards, Anil

      B Offline
      B Offline
      blakey404
      wrote on last edited by
      #2

      yes - when an instance of the class is created

      A 1 Reply Last reply
      0
      • B blakey404

        yes - when an instance of the class is created

        A Offline
        A Offline
        A M SOMAN
        wrote on last edited by
        #3

        Does that mean, when we include say System.Data.SQLClient namespace on the top of our class, it copies all the classes inside this namespace at runtime and allocates memory accordingly even if we don't use anything in it? Regards, Anil

        B N 2 Replies Last reply
        0
        • A A M SOMAN

          Does that mean, when we include say System.Data.SQLClient namespace on the top of our class, it copies all the classes inside this namespace at runtime and allocates memory accordingly even if we don't use anything in it? Regards, Anil

          B Offline
          B Offline
          blakey404
          wrote on last edited by
          #4

          no not when including the namespaces/classes, when instantiating them

          1 Reply Last reply
          0
          • A A M SOMAN

            Does that mean, when we include say System.Data.SQLClient namespace on the top of our class, it copies all the classes inside this namespace at runtime and allocates memory accordingly even if we don't use anything in it? Regards, Anil

            N Offline
            N Offline
            N a v a n e e t h
            wrote on last edited by
            #5

            A M SOMAN wrote:

            Does that mean, when we include say System.Data.SQLClient namespace on the top of our class, it copies all the classes inside this namespace at runtime and allocates memory accordingly

            It will allocate memory once you create instance for it. class1 c1; won't allocate any memory. But class1 c1 = new class1() will allocate memory space.


            My Website | Ask smart questions

            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