Only 49 hours left in the trailboss' kickstarter!

New rewards and stretch goals. CLICK HERE!



  • Post Reply Bookmark Topic Watch Topic
  • New Topic

lazy initialization  RSS feed

 
basia fish
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi

how do i use lazy initialization
how would it change code like this

private int array[];

public void setArray(int arr[])
{
array=arr;
}
public int[] getArray)()
{
return array;
}

help really apprecaited
thanks a lot
barb
 
Dipen Javia
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey barb,

I am sorry barb but i couldnt understand what you are trying to do with that code and I didnt understand the term "lazy initialization".
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lazy instantiation/initialisation means you don't initialise a member until the first time that member is requested somewhere.

Typically you'd have something like


Typically it's used when the initialisation of the data is expensive and won't be required for every instance of the class. Using lazy instantiation in such cases yields a performance win for many users of the class either by using less CPU cycles and/or less memory.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!