bodokaiser
bodokaiser

Reputation: 15752

For what do we need storage allocation?

for what do we actually require manual storage allocation?

The only possible tasks which I could think about would be for bigger binary data which does not fit to a 32bit integer.

Is this correct? What are other use cases?

Upvotes: 2

Views: 147

Answers (2)

Sergey Kalinichenko
Sergey Kalinichenko

Reputation: 726609

In general, you need to do manual storage allocation every time that the size of your data is not known at compile time. Almost all situations fall into two categories:

  • Your program must read data from files/networks/user inputs etc., and the exact amount of that data is not known at compile time, or
  • Your program must produce and store some output, and the exact amount of that output is not known to you at the time when you write your program.

Many very common data structures assume an ability to allocate memory of arbitrary size, when the precise size is determined at runtime. Doing so lets the data structure "grow" and "shrink" dynamically, as the storage demands of your program change with the time and the amounts of data that it processes.

Upvotes: 1

75inchpianist
75inchpianist

Reputation: 4102

tons of examples. Allocating memory to fill a struct, for example, a linked list struct.

Upvotes: 0

Related Questions