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. Static class with static member and memory allocation

Static class with static member and memory allocation

Scheduled Pinned Locked Moved C#
performancequestionlearning
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.
  • H Offline
    H Offline
    Herhighness
    wrote on last edited by
    #1

    Hi, I have a static class, and it contains a private static member for resource management. static class ConnectionManager { private static ResourceManager resmgr = new ResourceManager("myApplication.stringresources", Assembly.GetExecutingAssembly()); ---------- -------- '''''''''''' } initializing a static member this way, is this right way to do this? every time when this class is called, would it reinitialize the static member, creating new memory allocation? or would I have a single memory allocation alloted the first time class is refereneced? Thanks, herhighness

    J 1 Reply Last reply
    0
    • H Herhighness

      Hi, I have a static class, and it contains a private static member for resource management. static class ConnectionManager { private static ResourceManager resmgr = new ResourceManager("myApplication.stringresources", Assembly.GetExecutingAssembly()); ---------- -------- '''''''''''' } initializing a static member this way, is this right way to do this? every time when this class is called, would it reinitialize the static member, creating new memory allocation? or would I have a single memory allocation alloted the first time class is refereneced? Thanks, herhighness

      J Offline
      J Offline
      Jun Du
      wrote on last edited by
      #2

      Yes, it is a right way. The initialization of a static variable would be executed only once. You'll have the single memory allocated the first time class is refereneced.

      Best, Jun

      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