C++

new & delete

Në shqip përdoret i njëjti emër.

ShpjegimiSQ

Me new kërkon memorie gjatë ekzekutimit (në heap), dhe me delete e kthen kur s'të duhet më. Po harrove delete, memoria s'lirohet kurrë (memory leak). Në C++ modern përdor më shpesh vector ose smart pointers, që e bëjnë këtë vetë.

EnglishEN

With new you ask for memory while the program runs (on the heap), and with delete you give it back when you no longer need it. Forget delete and the memory is never freed (a memory leak). In modern C++ you more often use vector or smart pointers, which do this for you.

Si ta mendosh

Si të marrësh me qira një sallë për ditëlindje: po s'ia ktheve çelësat pronarit, salla mbetet e zënë përgjithmonë.

Lexoje në anglisht

Like renting a hall for a birthday: if you don't give the keys back, the hall stays booked forever.

Shembull kodicpp

int* notat = new int[30];   // 30 vende në heap
notat[0] = 5;
delete[] notat;             // kthe memorien

Terma të lidhur