Click here to Skip to main content
15,926,507 members
Home / Discussions / C#
   

C#

 
GeneralRe: Adding UserControl Pin
Christian Graus2-Feb-05 12:59
protectorChristian Graus2-Feb-05 12:59 
GeneralRe: Adding UserControl Pin
Luis Alonso Ramos2-Feb-05 16:18
Luis Alonso Ramos2-Feb-05 16:18 
GeneralWindows Services and .config files Pin
Esmo20002-Feb-05 8:54
Esmo20002-Feb-05 8:54 
GeneralRe: Windows Services and .config files Pin
Robert Rohde2-Feb-05 8:56
Robert Rohde2-Feb-05 8:56 
GeneralRe: Windows Services and .config files Pin
Esmo20002-Feb-05 9:22
Esmo20002-Feb-05 9:22 
GeneralRe: Windows Services and .config files Pin
mav.northwind2-Feb-05 19:58
mav.northwind2-Feb-05 19:58 
GeneralRe: Windows Services and .config files Pin
Esmo20003-Feb-05 3:25
Esmo20003-Feb-05 3:25 
GeneralCreate when you need it - best practices Pin
Judah Gabriel Himango2-Feb-05 8:27
sponsorJudah Gabriel Himango2-Feb-05 8:27 
I have a question that I'm sure some of the experts here will be able to answer. Smile | :)

I have a custom business object that, by itself, contains a small amount of data. However, during runtime, that object may create and hold more data depending on how it is used. Basically, I want the object to grow-on-the-fly rather than allocate everything all at once.

The way I've set this up is through a property in the object:

public BigStuff[] HugeData
{
   get
   {
      if (this.hugeData == null)
      {
          this.hugeData = new HugeData();
      }
      return this.hugeData;
   }
}


This way, hugeData is only allocated when it is needed.

Now to the problem: multithreading. This property has the potential to allocate hugeData multiple times if the get_HugeData method is called asynchronously from multiple threads. What is the best way to get around this? Currently, I've placed a [MethodImpl(MethodImplOptions.Synchronized)] tag on the getter of the property, but I don't know how efficient that is, or whether there's a better way to do this. Any thoughts?

Tech, life, family, faith: Give me a visit.
Judah Himango


GeneralRe: Create when you need it - best practices Pin
Robert Rohde2-Feb-05 8:54
Robert Rohde2-Feb-05 8:54 
GeneralRe: Create when you need it - best practices Pin
Judah Gabriel Himango2-Feb-05 8:58
sponsorJudah Gabriel Himango2-Feb-05 8:58 
GeneralRe: Create when you need it - best practices Pin
Robert Rohde2-Feb-05 9:09
Robert Rohde2-Feb-05 9:09 
GeneralRe: Create when you need it - best practices Pin
Judah Gabriel Himango2-Feb-05 9:27
sponsorJudah Gabriel Himango2-Feb-05 9:27 
GeneralRe: Create when you need it - best practices Pin
Judah Gabriel Himango2-Feb-05 9:59
sponsorJudah Gabriel Himango2-Feb-05 9:59 
GeneralMail Encoding using MailMessage Pin
[DAve]2-Feb-05 8:16
[DAve]2-Feb-05 8:16 
QuestionSystem.Exception: CFCC is an invalid expression???? Pin
Member 15229922-Feb-05 8:08
Member 15229922-Feb-05 8:08 
GeneralSettings Window Height Pin
Guinness4Strength2-Feb-05 8:06
Guinness4Strength2-Feb-05 8:06 
GeneralRe: Settings Window Height Pin
Robert Rohde2-Feb-05 8:22
Robert Rohde2-Feb-05 8:22 
GeneralRe: Settings Window Height Pin
Guinness4Strength2-Feb-05 8:29
Guinness4Strength2-Feb-05 8:29 
GeneralCustom MessageBox Buttons Pin
JMichael24682-Feb-05 6:47
JMichael24682-Feb-05 6:47 
GeneralRe: Custom MessageBox Buttons Pin
Robert Rohde2-Feb-05 9:02
Robert Rohde2-Feb-05 9:02 
GeneralExposing class library to COM Pin
Rein Petersen2-Feb-05 6:32
Rein Petersen2-Feb-05 6:32 
GeneralRe: Exposing class library to COM Pin
Judah Gabriel Himango2-Feb-05 8:34
sponsorJudah Gabriel Himango2-Feb-05 8:34 
GeneralConverting int / long to byte[] Pin
Tristan Rhodes2-Feb-05 4:22
Tristan Rhodes2-Feb-05 4:22 
GeneralRe: Converting int / long to byte[] Pin
Some Idiot2-Feb-05 4:39
Some Idiot2-Feb-05 4:39 
GeneralRe: Converting int / long to byte[] Pin
Tristan Rhodes2-Feb-05 6:27
Tristan Rhodes2-Feb-05 6:27 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.