Showing posts with label Dynamic memory allocation. Show all posts
Showing posts with label Dynamic memory allocation. Show all posts

Jun 13, 2020

 CODING WINDS  |   We care about the future of future

In the life of computer programmer, there have been always some or the other things or topics which they use them daily and still don’t have adequate knowledge about it. So for clearing this mess up of you, here we are working voluntarily. Do have a watch on us regularly.

C++ Programming :

1.    #include<iostream> | #include<iomanip> | Header files

2.    using namespace std;

3.    Dynamic Memory Allocation | malloc() | calloc() |realloc() | free()

4.   Asymptotic Analysis 

5.  Space Complexity    

6. Time Complexity             

7. Time Complexity Analysis and Calculation  

8. Time Limit Exceeded (TLE)        

9. What is a Data Structure?  

10. OOPs Concepts    

11. Pointers in C and C++ 

12. Errors | Runtime Error | Compile Error | Logical Error   

13. Arrays in C/C++    

14. Passing Arrays in Functions as Arguments

15. Structure in C++

16. Structures and Functions

17. Strings in C++

18. C++20

19. NULL Pointers in C/C++

20. Strings Pre-defined Functions

21. Inheritance

22. Functions

23. Constructors

24. Ceil and Floor Functions

25. abs() , labs() and llabs() Functions

26. Polymorphism in C++

27. Templates in C++

28. Destructors in C++

Python Language :-

        1. Python - Introduction

        2. Data Types in Python

        3.  Strings in Python


        5. format() Advanced

        6. Python List

        7. Python Tuple

         8. Data Type Conversion in Python

         9. List Comprehension

        10. Sets

        11. Dictionary
        
        12. Dictionary Comprehension

        13. Python Operators
           
        14. User Input

        15. Exception handling

            16. Functions

            17. Lambda and Arrays

        18. Modules

            19. File Handling 
            
        20. Map, Filter and Reduce

            21. Metaclasses

Java Language :

In near future we are going to come with many other such articles, follow us on instagram (@coding.winds) for future updates.


Jun 4, 2020

Dynamic Memory Allocation | malloc() | calloc() | free () | realloc() | Array of undefined size | Changing the size of an array using realloc() | CODING WINDS

  Dynamic Memory Allocation

 

Hey people in this blog you are going to read about “Dynamic Memory Allocation”, you need to know before you are using functions like “malloc()”, “calloc()”, “free()”, etc. in your C/C++ code.

To change or define the size of any data structure during the runtime is called “Dynamic Memory Allocation”.

To use Dynamic memory allocation we need to use several library functions

malloc() , calloc() , free() , realloc().  These operations are including in the library <stdlib.h> .

1.  malloc() function :

The name “malloc” stands for memory allocation.

SYNTAX  :  ptr = (CastType *)malloc(size);

The malloc() function reserves a block of memory of the specified number of bytes. And, it returns a pointer of void which can be casted into pointers of any form.

2.  calloc() function :

The name “calloc” stands for contiguous allocation.

The malloc() function allocates memory and leaves the memory uninitialized. Whereas, the calloc() function allocates memory and initializes all bits to zero.

 

SYNTAX  :  ptr = (CastType *)calloc(n,elements_size);

Where, n – number of elements

3.  free() function :

The dynamically allocated memory created either with either calloc() or malloc() does not get freed upon themselves. You must  explicitly use free() to release the space.

SYNTAX  :  free(ptr);

4.  realloc() function :

The name “realloc” stands for re-allocation.

“realloc” method in C is used to dynamically change the memory allocation of a previously allocated memory. In other words, if the memory previously allocated with the help of “malloc” or “calloc” is insufficient, “realloc” can be used to dynamically re-allocate memory. Re-allocation of memory maintains the already present value and new blocks will be initialized with default garbage value.

 

SYNTAX  :  ptr = realloc(ptr, NewSize);

 

It is hard to understand this topic by just reading this bookish deifinition.

So, let’s just look into some working examples of this, which might help get insight of this topic in a better way :

1.    Declaring an array of a variable size, using “malloc()“ function.

2.    Intializing an array of variable size with a zero value, using “calloc()” function.

3.    Deleting a memory space occupied by any data structure, using “free()” function.

4.    Re-defining the size of an array, using “realloc()”  function.

 

 

1.   Declaring an array of a variable size, using “malloc()“ function.

 

 

2.   Intializing an array of variable size with a zero value, using “calloc()” function.

 


 

3.   Deleting a memory space occupied by any data structure, using “free()” function.

 


4.   Re-defining the size of an array, using “realloc()”  function.