C
Sponsored Links
Basic Memory Management; Allocating and Resizing a Buffer
There are times when you don't know ahead of time how large of a buffer you need. The following code shows one approach to dynamically allocating and resizing a buffer. Note that passing a NULL pointer to "realloc" has the same effect as calling "malloc". If the call to "realloc" fails, it will return a NULL pointer. The following sample works with a buffer of integer values.
| # | Coder Name | Hits |
| 1. | kaivalya1989 | 33967 |
| 2. | mano.mithun | 21650 |
| 3. | deepu08 | 17875 |
| 4. | meefriend4ever | 8124 |
| 5. | chandrikakr | 8092 |
| 6. | sadasivathavamani | 7363 |
| 7. | shashivaishnav | 7162 |
| 8. | venkatakrishnansvpr | 7078 |
| 9. | Jimmy Zorald | 6713 |
| 10. | sripri | 5712 |
| # | Coder Name | Codes |
| 1. | kaivalya1989 | 4 |
| 2. | mano.mithun | 3 |
| 3. | sripri | 1 |
| 4. | sadasivathavamani | 1 |
| 5. | Jimmy Zorald | 1 |
| 6. | jbode | 1 |
| 7. | norman | 1 |
| 8. | Rajani | 1 |
| 9. | meefriend4ever | 1 |
| 10. | chandrikakr | 1 |