Saturday, March 24, 2012
Yerellik Düzeyi (Locality)
Görev isletiminin, belirli bir adres bölgesinde ne kadar süreyle kaldığı, görevin yerellik düzeyi (locality) ile açıklanır
what's trashing?
İsletim sisteminin eksik sayfa uyarılarının gerektirdiği islemlerle yoğun bir biçimde uğrasmaya baslamasına,trashing denir.
A process that is spending more time paging than executing is said to be thrashing.
http://www.cs.uic.edu/~jbell/CourseNotes/OperatingSystems/9_VirtualMemory.html
A process that is spending more time paging than executing is said to be thrashing.
http://www.cs.uic.edu/~jbell/CourseNotes/OperatingSystems/9_VirtualMemory.html
what's working set?
Working Set (WS), bir görevin, belirli bir zaman aralığı içinde, eksik sayfa uyarısı üretmeden çalısabileceği en küçük sayfa takımıdır.
what's belady anomaly?
The Belady's anomaly accurs in case of the FIFO page replacement policy in the OS.
When this FIFO is used and the number of page frames are increased in number, then the frames that are required by the program varies in a large range(due to large no of pages) as a result of this the number of page faults increases with the number of frames.
In computer storage, Belady's anomaly states that it is possible to have more page faults when increasing the number of page frames while using FIFO method of frame management. Laszlo Belady demonstrated this in 1969. Previously, it was believed that an increase in the number of page frames would always provide the same number or fewer page faults.
http://www.foddalo.com/viewtopic.php?f=18&t=277
Belady Anormalliği
Bazen bir göreve ayrılan bos sayfa sayısı artırılsa bile eksik sayfa uyarısı artabilir. Buna Belady anormalliği denir.
Çünkü, görevlere ayrılan sayfa sayısı artırılırsa, sistemde görev sayısının çok olduğu durumlarda, bellekte bos sayfa bulmak zorlasacaktır.
Görevlere aynı anda atanabilecek sayfa sayısı, genelde eksik sayfa uyarısı sayısı taban alınarak isletim sistemince belirlenir.
http://web.cs.hacettepe.edu.tr/~abc/teaching/bil324/slides/BIL324_01_6.pdf
When this FIFO is used and the number of page frames are increased in number, then the frames that are required by the program varies in a large range(due to large no of pages) as a result of this the number of page faults increases with the number of frames.
In computer storage, Belady's anomaly states that it is possible to have more page faults when increasing the number of page frames while using FIFO method of frame management. Laszlo Belady demonstrated this in 1969. Previously, it was believed that an increase in the number of page frames would always provide the same number or fewer page faults.
http://www.foddalo.com/viewtopic.php?f=18&t=277
Belady Anormalliği
Bazen bir göreve ayrılan bos sayfa sayısı artırılsa bile eksik sayfa uyarısı artabilir. Buna Belady anormalliği denir.
Çünkü, görevlere ayrılan sayfa sayısı artırılırsa, sistemde görev sayısının çok olduğu durumlarda, bellekte bos sayfa bulmak zorlasacaktır.
Görevlere aynı anda atanabilecek sayfa sayısı, genelde eksik sayfa uyarısı sayısı taban alınarak isletim sistemince belirlenir.
http://web.cs.hacettepe.edu.tr/~abc/teaching/bil324/slides/BIL324_01_6.pdf
sinav sorulari-1
Örnek 1.2.1 : 1'den 100'e kadar olan sayıların toplamını veren algoritma.
1. Toplam T, sayılar da i diye çağırılsın.
2. Başlangıçta T'nin değeri 0 ve i'nin değeri 1 olsun.
3. i'nin değerini T'ye ekle.
4. i'nin değerini 1 arttır.
5. Eğer i'nin değeri 100'den büyük değil ise 3. adıma git.
6. T'nin değerini yaz.
Aynı algoritmayı aşağıdaki gibi yazabiliriz.
1. T=0 ve i=0
2. i'nin değerini T'ye ekle.
3. i'yi 1 arttır.
4. i<101 ise 2.adıma git.
5. T'nin değerini yaz.
Örnek 1.2.3 : İki tamsayının çarpma işlemini sadece toplama işlemi kullanarak gerçekleyin.
Girdi : iki tamsayı
Çıktı : sayıların çarpımı
1. a ve b sayılarını oku
2. c =0
3. b>0 olduğu sürece tekrarla
.3.1. c=c + a
3.2. b = b-1
4. c değerini yaz ve dur
Örnek 1.2.4 : Bir tamsayının faktoriyelini hesaplayınız.
Girdi : Bir tamsayı
Çıktı : sayının faktoriyel
İlgili formul: Faktoriyel(n)=1*2*...*n
1. n değerini oku
2. F=1
3. n >1 olduğu sürece tekrarla
.3.1. F=F*n
3.2. n= n-1
4. F değerini yaz
Örnek 1.2.5 : İki tamsayının bölme işlemini sadece çıkarma işlemi kullanarak gerçekleyin. Bölüm ve kalanın ne olduğu bulunacak.
1. a ve b değerlerini oku
2. m=0
3. a>=b olduğu sürece tekrarla
3.1 a=a-b
3.2 m = m + 1
4. kalan a ve bölüm m 'yi yaz
Kaynak:
http://www.izafet.com/c-ve-c/93459-c-dili-kullanarak-bilgisayar-programlama.html#ixzz1q2jZw7WZ
Bilgisayar belle inde bulunan n x n boyutlar ndaki bir A matrisinin
transpozesini (devri ini) al p (B=AT), bunu form üzerinde matris format nda
yazd ran bir program yaz n z.
For i=1 To n
For j=1 To n
B(i,j)=A(j,i)
Next i
Next j
For i=1 To n
For j=1 To n
Print B(i,j),
Next i
Print
Next j
“notlar.txt” isimli dosyada 1. s n f ö rencilerinin Bilgisayar Programlama
dersine ait numara, ad-soyad ve 1.vize not bilgileri bulunmaktad r. Bu dosyay
kullanarak, bu ders için minimum, maksimum ve ortalama notu hesaplay p,
Picture1 nesnesine yazd ran program olu
turunuz
N=100 ‘Ö renci say s
ReDim V1(N)
For i=1 To N
Input #1, no, ad, V1(i)
Toplam=Toplam+V1(i)
Next i
Close #1
Ort=Toplam/N
Max=V1(1)
Min=V1(1)
For i=1 to N
If V1(i)>Max Then Max=V1(i)
If V1(i)
main()
{
int i,sayi,ek=100,eb=-100,ta=0, cifta=0;
double tek=0.0;
for(i=0; i<5; i++)
{
scanf("%d",&sayi);
if (sayi>eb) eb=sayi;
if (sayi
void dca(int en,int boy, int *cevre, int *alan)
{
*cevre=2*en+2*boy;
*alan=en*boy;
}
int main()
{
int en,boy,C,A;
printf ("Dikdörtgene ait en ve boyu girin :");
scanf("%d %d",&en,&boy);
dca(en,boy,&C,&A);
printf("Dikdörtgenin çevresi=%3d \n Alanı=%3d",C,A);
return 0;
}
13. Ogrenci isimli sınıfta, parametre olarak dışarıdan String ve boolean türünde değişken alan sadece bir
constructor tanımlanmıştır. Bu sınıftan bir nesne yapmak istiyoruz. Aşağıdaki seçeneklerden hangisi
doğrudur? [5 puan]
a. Ogrenci = new Ogrenci();
b. Ogr = Ogrenci(“java”, “true”);
c. Ogrenci ogr = new Ogrenci(“tobb”, false);
d. Ogrenci ogr = new Ogrenci(“true”);
e. Ogrenci ogr = Ogrenci(“tobb”, true);
http://w3.gazi.edu.tr/web/akcayol/files/JavaOrnekVize.pdf
1. Toplam T, sayılar da i diye çağırılsın.
2. Başlangıçta T'nin değeri 0 ve i'nin değeri 1 olsun.
3. i'nin değerini T'ye ekle.
4. i'nin değerini 1 arttır.
5. Eğer i'nin değeri 100'den büyük değil ise 3. adıma git.
6. T'nin değerini yaz.
Aynı algoritmayı aşağıdaki gibi yazabiliriz.
1. T=0 ve i=0
2. i'nin değerini T'ye ekle.
3. i'yi 1 arttır.
4. i<101 ise 2.adıma git.
5. T'nin değerini yaz.
Örnek 1.2.3 : İki tamsayının çarpma işlemini sadece toplama işlemi kullanarak gerçekleyin.
Girdi : iki tamsayı
Çıktı : sayıların çarpımı
1. a ve b sayılarını oku
2. c =0
3. b>0 olduğu sürece tekrarla
.3.1. c=c + a
3.2. b = b-1
4. c değerini yaz ve dur
Örnek 1.2.4 : Bir tamsayının faktoriyelini hesaplayınız.
Girdi : Bir tamsayı
Çıktı : sayının faktoriyel
İlgili formul: Faktoriyel(n)=1*2*...*n
1. n değerini oku
2. F=1
3. n >1 olduğu sürece tekrarla
.3.1. F=F*n
3.2. n= n-1
4. F değerini yaz
Örnek 1.2.5 : İki tamsayının bölme işlemini sadece çıkarma işlemi kullanarak gerçekleyin. Bölüm ve kalanın ne olduğu bulunacak.
1. a ve b değerlerini oku
2. m=0
3. a>=b olduğu sürece tekrarla
3.1 a=a-b
3.2 m = m + 1
4. kalan a ve bölüm m 'yi yaz
Kaynak:
http://www.izafet.com/c-ve-c/93459-c-dili-kullanarak-bilgisayar-programlama.html#ixzz1q2jZw7WZ
Bilgisayar belle inde bulunan n x n boyutlar ndaki bir A matrisinin
transpozesini (devri ini) al p (B=AT), bunu form üzerinde matris format nda
yazd ran bir program yaz n z.
For i=1 To n
For j=1 To n
B(i,j)=A(j,i)
Next i
Next j
For i=1 To n
For j=1 To n
Print B(i,j),
Next i
Next j
“notlar.txt” isimli dosyada 1. s n f ö rencilerinin Bilgisayar Programlama
dersine ait numara, ad-soyad ve 1.vize not bilgileri bulunmaktad r. Bu dosyay
kullanarak, bu ders için minimum, maksimum ve ortalama notu hesaplay p,
Picture1 nesnesine yazd ran program olu
turunuz
N=100 ‘Ö renci say s
ReDim V1(N)
For i=1 To N
Input #1, no, ad, V1(i)
Toplam=Toplam+V1(i)
Next i
Close #1
Ort=Toplam/N
Max=V1(1)
Min=V1(1)
For i=1 to N
If V1(i)>Max Then Max=V1(i)
If V1(i)
main()
{
int i,sayi,ek=100,eb=-100,ta=0, cifta=0;
double tek=0.0;
for(i=0; i<5; i++)
{
scanf("%d",&sayi);
if (sayi>eb) eb=sayi;
if (sayi
void dca(int en,int boy, int *cevre, int *alan)
{
*cevre=2*en+2*boy;
*alan=en*boy;
}
int main()
{
int en,boy,C,A;
printf ("Dikdörtgene ait en ve boyu girin :");
scanf("%d %d",&en,&boy);
dca(en,boy,&C,&A);
printf("Dikdörtgenin çevresi=%3d \n Alanı=%3d",C,A);
return 0;
}
13. Ogrenci isimli sınıfta, parametre olarak dışarıdan String ve boolean türünde değişken alan sadece bir
constructor tanımlanmıştır. Bu sınıftan bir nesne yapmak istiyoruz. Aşağıdaki seçeneklerden hangisi
doğrudur? [5 puan]
a. Ogrenci = new Ogrenci();
b. Ogr = Ogrenci(“java”, “true”);
c. Ogrenci ogr = new Ogrenci(“tobb”, false);
d. Ogrenci ogr = new Ogrenci(“true”);
e. Ogrenci ogr = Ogrenci(“tobb”, true);
http://w3.gazi.edu.tr/web/akcayol/files/JavaOrnekVize.pdf
Is memory leak possible in Java?
In any programming language, application-level memory management problems revolve around the deallocation of memory.
These problems fall into two categories:
premature deallocation (corrupted pointers) and incomplete deallocation (memory leaks).
In the case of incomplete deallocation, there are two subcases:
coding bugs and design bugs.
Coding bugs are language dependent.
In the case of C, this would involve free()ing less than was malloc()ed,
while in C++ this might involve using delete in lieu of delete[].
Design bugs, on the other hand, do not depend on the language;
instead, they involve simple programmer negligence.
In languages like C/C++, all memory management is handled by the programmer, so all of these problems can arise
the Java language and runtime together entirely eliminate the problems of corrupted pointers and code-level memory leaks.Here's how:
1-In Java, memory is allocated only to objects. There is no explicit allocation of memory, there is only the creation of new objects. (Java even treats array types as objects.)
2-The Java runtime employs a garbage collector that reclaims the memory occupied by an object once it determines that object is no longer accessible.
This automatic process makes it safe to throw away unneeded object references because the garbage collector does not collect the object if it is still needed elsewhere.
Therefore, in Java the act of letting go of unneeded references never runs the risk of deallocating memory prematurely.
3-In Java, it's easy to let go of an entire "tree" of objects by setting the reference to the tree's root to null; the garbage collector will then reclaim all the objects (unless some of the objects are needed elsewhere).
This is a lot easier than coding each of the objects' destructors to let go of its own dependencies (which is a coding-level problem with C++).
what about memory leaks caused by poor program design?
unnecessary object references originating in long-lived parts of the system prevent the garbage collector from reclaiming objects that are in fact no longer needed.
Another design flaw occurs "in the small," at the level of a faulty algorithm; the use of Collections objects in such cases will typically magnify the error.
As the technology improves, a suitably implemented JVM could help reduce the effects of such designed-in memory leaks by using the garbage collector to track object usage over time.
In conclusion: Design problems can be mitigated by letting go of object references in one's own classes as soon as one can
References:
http://www.javaworld.com/javaworld/javaqa/1999-08/04-qa-leaks.html?page=2
http://olex.openlogic.com/wazi/2009/how-to-fix-memory-leaks-in-java/
But sometimes if there is java.lang.OutOfMemoryError Exception , memory leak is certainly strong suspect.
IF any application eats more & more system memory and never seems to return memory back to the system untill large amount ot physical memory allocation to that application then this is the sign of memory leak.
Also there is a common problem when we register a class as an event listener without bothering to unregister when the class is no longer needed.
We can prevent memory leaks by watching for some common problems
Collection classes, such as hashtables and vectors, are common places to find the cause of a memory leak
This is particularly true if the class has been declared static and exists for the life of the application. and many times member variables of a class that point to other classes simply need to be set to null at the appropriate time.
Reference:
http://www.erpgreat.com/java/memory-leak-in-java.htm
http://stackoverflow.com/questions/6470651/creating-a-memory-leak-with-java
http://www.youtube.com/watch?v=Dy7WZv5bEV4
http://www.youtube.com/watch?v=jy39JEBSPkI
http://www.youtube.com/watch?v=YB2xvYCY4B8
http://www.youtube.com/watch?v=3p-rwnJlGMY
memory leak will occur if you put too many objects on the heap, I think that most of the time it will happen when you have some kind of a data structure and you keep on filling it while not removing unneeded objects.
For example, let say I'm keeping a Hash that contains all the phones that are currently in my factory.
If I forget to remove phones that left the factory towards customers - A memory leak exists in my program, since the hash will keep on growing. This is also the place to mention that some data structures (such as hash and arraylist) are doubling their sizes when they reach some predefined factor and so I can even run out of memory before I even use the entire potential of it holding my phones...
more common example would be if you hold connections to your server and forget to close them and remove them from your connection pool
http://www.linkedin.com/groups/What-is-Memory-Leak-in-70526.S.208104654?view=&gid=70526&type=member&item=208104654&trk=eml-anet_dig-b_nd-pst_ttle-cn
a good way to create a true memory leak (objects inaccessible by running code but still stored in memory) in pure Java:
1-The application creates a long-running thread (or use a thread pool to leak even faster).
why application containers (like Tomcat) can leak memory like sieve if you frequently redeploy applications that happen to use ThreadLocals in any way.
(Since the application container uses Threads as described, and each time you redeploy the application a new ClassLoader is used.)
http://stackoverflow.com/questions/6470651/creating-a-memory-leak-with-java
These problems fall into two categories:
premature deallocation (corrupted pointers) and incomplete deallocation (memory leaks).
In the case of incomplete deallocation, there are two subcases:
coding bugs and design bugs.
Coding bugs are language dependent.
In the case of C, this would involve free()ing less than was malloc()ed,
while in C++ this might involve using delete in lieu of delete[].
Design bugs, on the other hand, do not depend on the language;
instead, they involve simple programmer negligence.
In languages like C/C++, all memory management is handled by the programmer, so all of these problems can arise
the Java language and runtime together entirely eliminate the problems of corrupted pointers and code-level memory leaks.Here's how:
1-In Java, memory is allocated only to objects. There is no explicit allocation of memory, there is only the creation of new objects. (Java even treats array types as objects.)
2-The Java runtime employs a garbage collector that reclaims the memory occupied by an object once it determines that object is no longer accessible.
This automatic process makes it safe to throw away unneeded object references because the garbage collector does not collect the object if it is still needed elsewhere.
Therefore, in Java the act of letting go of unneeded references never runs the risk of deallocating memory prematurely.
3-In Java, it's easy to let go of an entire "tree" of objects by setting the reference to the tree's root to null; the garbage collector will then reclaim all the objects (unless some of the objects are needed elsewhere).
This is a lot easier than coding each of the objects' destructors to let go of its own dependencies (which is a coding-level problem with C++).
what about memory leaks caused by poor program design?
unnecessary object references originating in long-lived parts of the system prevent the garbage collector from reclaiming objects that are in fact no longer needed.
Another design flaw occurs "in the small," at the level of a faulty algorithm; the use of Collections objects in such cases will typically magnify the error.
As the technology improves, a suitably implemented JVM could help reduce the effects of such designed-in memory leaks by using the garbage collector to track object usage over time.
In conclusion: Design problems can be mitigated by letting go of object references in one's own classes as soon as one can
References:
http://www.javaworld.com/javaworld/javaqa/1999-08/04-qa-leaks.html?page=2
http://olex.openlogic.com/wazi/2009/how-to-fix-memory-leaks-in-java/
- Actually there is not to worry about the memory leak in Java.It is handled by Garbage Collector in Java.
But sometimes if there is java.lang.OutOfMemoryError Exception , memory leak is certainly strong suspect.
IF any application eats more & more system memory and never seems to return memory back to the system untill large amount ot physical memory allocation to that application then this is the sign of memory leak.
Also there is a common problem when we register a class as an event listener without bothering to unregister when the class is no longer needed.
We can prevent memory leaks by watching for some common problems
Collection classes, such as hashtables and vectors, are common places to find the cause of a memory leak
This is particularly true if the class has been declared static and exists for the life of the application. and many times member variables of a class that point to other classes simply need to be set to null at the appropriate time.
Reference:
http://www.erpgreat.com/java/memory-leak-in-java.htm
http://stackoverflow.com/questions/6470651/creating-a-memory-leak-with-java
- Java Memory Leak Detection with JProfiler
http://www.youtube.com/watch?v=Dy7WZv5bEV4
- Java Performance - Eclipse.mp4
http://www.youtube.com/watch?v=jy39JEBSPkI
- Intertech - Complete Java Performance Tuning Training - Part 1
http://www.youtube.com/watch?v=YB2xvYCY4B8
- Plumbr - a tool for preventing and solving Java memory leaks
http://www.youtube.com/watch?v=3p-rwnJlGMY
- What is Memory Leak in java?
memory leak will occur if you put too many objects on the heap, I think that most of the time it will happen when you have some kind of a data structure and you keep on filling it while not removing unneeded objects.
For example, let say I'm keeping a Hash that contains all the phones that are currently in my factory.
If I forget to remove phones that left the factory towards customers - A memory leak exists in my program, since the hash will keep on growing. This is also the place to mention that some data structures (such as hash and arraylist) are doubling their sizes when they reach some predefined factor and so I can even run out of memory before I even use the entire potential of it holding my phones...
more common example would be if you hold connections to your server and forget to close them and remove them from your connection pool
http://www.linkedin.com/groups/What-is-Memory-Leak-in-70526.S.208104654?view=&gid=70526&type=member&item=208104654&trk=eml-anet_dig-b_nd-pst_ttle-cn
- Creating a memory leak with Java
a good way to create a true memory leak (objects inaccessible by running code but still stored in memory) in pure Java:
1-The application creates a long-running thread (or use a thread pool to leak even faster).
why application containers (like Tomcat) can leak memory like sieve if you frequently redeploy applications that happen to use ThreadLocals in any way.
(Since the application container uses Threads as described, and each time you redeploy the application a new ClassLoader is used.)
http://stackoverflow.com/questions/6470651/creating-a-memory-leak-with-java
Is http stateful or stateless?
HTTP as a protocol is stateless. In general, though, a stateless protocol can be made to act as if it were stateful, assuming you've got help from the client
This happens by arranging for the server to send the state to the client, and for the client to send it back again next time
There are three ways this happens in HTTP.
One is cookies, in which case the state is sent and returned in HTTP headers
The second is URL rewriting, in which case the state is sent as part of the response and returned as part of the request URI
The third is hidden form fields, in which the state is sent to the client as part of the response, and returned to the server as part of a form's data
(which can be in the request URI or the POST body, depending on the form's method).
Reference:
http://www.velocityreviews.com/forums/t149832-is-http-stateful-or-stateless.html
Introduction to HTTP Preview
http://www.youtube.com/watch?v=xpBpGC08f4Q
Lesson: Hypertext Transport Protocol Overview (HTTP) - Part 1
http://www.youtube.com/watch?v=iySa4zBYScE
This happens by arranging for the server to send the state to the client, and for the client to send it back again next time
There are three ways this happens in HTTP.
One is cookies, in which case the state is sent and returned in HTTP headers
The second is URL rewriting, in which case the state is sent as part of the response and returned as part of the request URI
The third is hidden form fields, in which the state is sent to the client as part of the response, and returned to the server as part of a form's data
(which can be in the request URI or the POST body, depending on the form's method).
Reference:
http://www.velocityreviews.com/forums/t149832-is-http-stateful-or-stateless.html
Introduction to HTTP Preview
http://www.youtube.com/watch?v=xpBpGC08f4Q
Lesson: Hypertext Transport Protocol Overview (HTTP) - Part 1
http://www.youtube.com/watch?v=iySa4zBYScE