Jay
Jay

Reputation: 77

C: allocation limits

I am trying to allocate ~ 1GB , but when I check the pointer address it's a negative number. Could this be a configuration limit I am hitting somewhere.

Upvotes: 1

Views: 136

Answers (2)

Šimon Tóth
Šimon Tóth

Reputation: 36451

but when I check the pointer address it's a negative number

That's not possible. What you might see is interpretation of the address as a signed integer.

There is no limit embedded in C itself. The allocations are limited by the data type used for requested block size and addressing capability of the operating system.

During runtime the request will fail (malloc() returning NULL) if there is not a continuous block of free memory of the requested size.

Upvotes: 1

Mat
Mat

Reputation: 206909

Don't test for a pointer's "sign", it's irrelevant. The only invalid pointer that malloc will return is the null pointer. If it returned something else, you can use it.

Upvotes: 7

Related Questions