JOIN us on
WhatsApp Group Join Now
Telegram Join Join Now

हिंदी माध्यम नोट्स

Class 6

Hindi social science science maths English

Class 7

Hindi social science science maths English

Class 8

Hindi social science science maths English

Class 9

Hindi social science science Maths English

Class 10

Hindi Social science science Maths English

Class 11

Hindi sociology physics physical education maths english economics geography History

chemistry business studies biology accountancy political science

Class 12

Hindi physics physical education maths english economics

chemistry business studies biology accountancy Political science History sociology

Home science Geography

English medium Notes

Class 6

Hindi social science science maths English

Class 7

Hindi social science science maths English

Class 8

Hindi social science science maths English

Class 9

Hindi social science science Maths English

Class 10

Hindi Social science science Maths English

Class 11

Hindi physics physical education maths entrepreneurship english economics

chemistry business studies biology accountancy

Class 12

Hindi physics physical education maths entrepreneurship english economics

chemistry business studies biology accountancy

Categories: C Language in hindi

Dynamic Memory Allocation : Malloc in hindi डाइनेमिक मेमोरी एलोकेशन : मलोक क्या होता है c भाषा में

डाइनेमिक मेमोरी एलोकेशन : मलोक क्या होता है c भाषा में Dynamic Memory Allocation : Malloc in hindi :-
कई बार प्रोग्रामिंग मे dynamic data की जरुरत पड़ती है |इसका मतलब है की variable द्वारा ली जनि वाली value की size एक्षेकुतिओन के समय change हो सकती है |उदाहरण के लिए :
किसी प्रोग्राम मे , एक क्रिकेट टीम के प्लेयर की last matches मे performance के data को store करते है |ये लिस्ट बढती जब प्लेयर को add होगा और छोटी होगी जब प्लेयर डिलीट होगा
इस प्रकार मे , जब लिस्ट बढती है ,तब लिस्ट के लिए memory space को बढ़ा देगे |
इस प्रोसेस को Dynamic Memory Allocation से handel कर सकते है |
Dynamic data structure run time मे adding,deletion और rearraning करना आसान हो जाता है |Dynamic Memory Allocation मे , किसी additional memory space allocate करेगे और unwanted space को डिलीट कर सकते है |Dynamic Memory Allocation:
C language मे , array की size को compile time पर define करना होता है |लेकिन array की size को run time से पहले पता लगना मुश्किल होता है |अगर गलत size होने पर दो प्रॉब्लम हो सकती है :-
1.अगर बड़ी size हो तब memory wastage हो जाती है |
2.अगर छोटी size हो तब प्रोग्राम terminate हो जाता है |
कई language मे , array के लिए memory run time पर allocate कर सकते है |in language मे array की size को run time पर calculate और assign कर सकते है |अतः memory dynamic variable की अवसकता होती है |run time पर memory को allocate करना को Dynamic Memory Allocation कहते है |
C languge मे, Dynamic Memory Allocation के लिए चारfunction  होते है :-
1.malloc ()
इस function का use ,run time पर किसी variable को बाइट या size ऑफ़ bytes allocate करता है और in size ऑफ़ बाइट के पहले बाइट की address को pointer variable को देता है |
2.calloc()
इस function से array के element के लिए space को allocate कर सकते है और array के पहले element के address को pointer variable को return करता  है |
3.free ()
इस function का use ,allocate space को फ्री कर देता है |
4.relloc()
इस function का use allocate space को modify करने के लिए कर सकते है|


Memory Allocation Process
उन  function को सार मे पढने से पहले ,हम memory allocation process को पढ़ेगे |अतः global variable और statement ,c प्रोग्राम के permenent storage मे सेव होता है |और local variable stack मे सेव होता है |इन दोनों space के बीच जो memory space होता है |इस memory space को memory allocation के लिए इस्तेमाल हो सकता है |इस फ्री space को heap कहते है |
इस heap की size change हो सकते जब कोई नए variable को create और delete कर सकते है |जब ये space overfull हो जाता है tab dynamic function null pointer return करेगा |

Malloc Function
इस function से memory block allocate हो जाता है | Malloc function memory space मे एक specific  memory block को allocate करता है और void त्य्प एक pointer return करता है |इसका syntax है :-

pointer_name = (cast type *) malloc(byte-size);

यहा पर :
pointer_name :  pointer _name उस pointer का नाम है जिसमे malloc function से return value store होगी |
cast type * : ये pointer_name का type को define करता है |
byte-size : ये memory block की size को define करता है |

इसका उदाहरण है :-
a=(char *) malloc (200* sizeof(int));

इसstatement से एक charecter type का pointer variable ‘a’  allocate होता है |memory block की size 200 time of size of  integer byte(2 byte in normal) होगी |और malloc function से पहले बाइट का address pointer variable ‘a’ मे store हो जाता है|

उदहारण 2
a=(char *) malloc (13);

इस statement से 13 byte का memory block allocate हो जाता है |जिसक पहले बाइट का address pointer variable ‘a’ मे store हो जाता है |

malloc() function का use structure के साथ भी कर सकते है |इसका syntax होता है :-

pointer_variable = (Structue_ name *) malloc( sizeof(structure_name));

यहाँ पर :
pointer_name :  pointer _name उस pointer का नाम है जिसमे malloc function से return value store होगी |
cast type * : ये pointer_name का type को define करता है |structure के लिए structure variable का नाम ही cast type होता है |
sizeof(structure_name) : ये memory block की size को define करता है |ये structure की size को define करता है |

उदाहरन के लिए :

struct_variable=(struct person *) malloc(10*sizeof(structperson));

इस statement से , 10 time of structure variable के size का memory block allocate हो जायेगा |जिसम इसे पहले structure के पहले member का address pointer variable struct_variable मे assign हो जाये गा |

अगर heap(free space ) overfull हो जाता है |तब memory allocation possible नहीं हो पता है |और malloc function null pointer को pointer variable की value assign कर देता है |

उदहारण :
#include<stdio>
#include<conio.h>
void main(0
{
int *p,*t;
int s;
printf(“Enter Size of table “);
scanf(“%d”,&s);

if(t=(int *)malloc(s*sizeof(int))==NULL)
{
printf(“No more space “);
}
else
{
printf(“Address of First table byte=%u\n”,t);
}
printf(“Table data”);
for(p=t;p<t+s;p++)
{
scanf(“%d”,p);
printf(“%d is store at %u\n”,*p,p);
}
getch();
}

इस उदाहरन में,
यूजर से table के size को input लिया गया है |
फिर pointer variable ‘t’ मे malloc function से 7 time of integer का  memory block allocate  हो जायेगा  |जैसे यूजर द्वारा input size ‘7’ होती तो 7*size (int) =14 bytes का memory block allocate हो जायेगा  |

आउटपुट होगा :
Enter Size of table 7
Address of First table byte=1020
Table data 12 34 45 54 45 65 56
12 is store at 1020
34 is store at 1022
45 is store at 1024
54 is store at 1026
45 is store at 1028
65 is store at 1030
56 is store at 1032

अब आगे article मे Dynamic Memory Allocation : Calloc ,Relloc और free मे Dynamic Memory Allocation के बाकि तीन functions को पढेगे |

Sbistudy

Recent Posts

द्वितीय कोटि के अवकल समीकरण तथा विशिष्ट फलन क्या हैं differential equations of second order and special functions in hindi

अध्याय - द्वितीय कोटि के अवकल समीकरण तथा विशिष्ट फलन (Differential Equations of Second Order…

11 hours ago

four potential in hindi 4-potential electrodynamics चतुर्विम विभव किसे कहते हैं

चतुर्विम विभव (Four-Potential) हम जानते हैं कि एक निर्देश तंत्र में विद्युत क्षेत्र इसके सापेक्ष…

3 days ago

Relativistic Electrodynamics in hindi आपेक्षिकीय विद्युतगतिकी नोट्स क्या है परिभाषा

आपेक्षिकीय विद्युतगतिकी नोट्स क्या है परिभाषा Relativistic Electrodynamics in hindi ? अध्याय : आपेक्षिकीय विद्युतगतिकी…

5 days ago

pair production in hindi formula definition युग्म उत्पादन किसे कहते हैं परिभाषा सूत्र क्या है लिखिए

युग्म उत्पादन किसे कहते हैं परिभाषा सूत्र क्या है लिखिए pair production in hindi formula…

1 week ago

THRESHOLD REACTION ENERGY in hindi देहली अभिक्रिया ऊर्जा किसे कहते हैं सूत्र क्या है परिभाषा

देहली अभिक्रिया ऊर्जा किसे कहते हैं सूत्र क्या है परिभाषा THRESHOLD REACTION ENERGY in hindi…

1 week ago
All Rights ReservedView Non-AMP Version
X

Headline

You can control the ways in which we improve and personalize your experience. Please choose whether you wish to allow the following:

Privacy Settings
JOIN us on
WhatsApp Group Join Now
Telegram Join Join Now