Core’u geniş Tutki Patlamasın :) (Segmentation Fault Core Dumped C++)
, Ödev, Belçika, C++, Core Dumped, English, Linux, Memory Allocating Sende Yorum Yapİngilizce bilen kardeşler için bir açıklama yapayım
( maksat sitenin gavur ziyaretçiside olsun
)
For English Press 9:
I was coding a small program on C++ then I have the error;
master@slave:~/project/oop2$ g++ MyString.cc MyString.h -o trial
master@slave:~/project/oop2$ ./trial
Segmentation fault (core dumped)
It was because using a pointer without specifying its borders. It grows and grows then it violates the memory addresses belonged by other variables, methods or what ever. The solution is simple just reserving the needed memory. So how to do that? The answer is also simple. You should allocate the memory using malloc() function which is both available in C and C++.
for example you need a pointer to put inside 100 int.
int somenumber = 100; // the number of integer you will put in pointer
int *intPointer;
intPointer = (int *)malloc(somenumber * sizeof(int));
// malloc function needs the byte value of the needed area in memory
// that’s why you should multiply it with the byte value of an integer
// it is generally 4 in 32-bit and 64-bit processor aimed compilers
Don’t press 8 it is for Dutch :D, my Dutch is still poor,
Press 7 for Turkish
Evet Türkçesine gelince olayın, Tercüme edin Allah Allah, beni uğraştırmayın :).
Neyse ben biraz bahsedeyim yine :);
Yazdığım programda bir adet int pointer kullanıyordum (çok adet te bir tanesi patlıyordu :)) ve bu memoryde sınırlarını zorluyordu, hatta altüst edip programımı öldürüyordu. Aslında çok basit bir problem ama yeni başlayanların ve benim gibi unutup tekrar hatırlayanların sık karşılaştıkları ve harşılaşacakları bir problem bu.
Tek yapılması gereken ise işinize yarayacak kadar memory’i o değişken için ayırmanız. Bu işlem için örnek kod yukarda.
Umarım googledan gelen arkadaşların işine yarar, ve bana bol bol ziyaretçi getirir
3 Ocak, 2008 tarihinde 12:03 pm Sularında
Fani işler İsmail bunlar ….
3 Ocak, 2008 tarihinde 12:05 pm Sularında
Bir temana gıcık oldum. Elma armut olaylarına girmişin…. Ben blog yazıyom apple a kıl oluyom diye sen apple cı cıkacan yakında. Birde ecnebi memleketinden ucuz apple ile gelirsinde ben seni görürüm…
9 Ocak, 2008 tarihinde 1:29 pm Sularında
Ama şöyle kelepir bi G5 geçse elime hayır demem yani
11 Ocak, 2008 tarihinde 2:35 pm Sularında
Beleşin gözü kör olsun …