Nikunj Banka
Nikunj Banka

Reputation: 11365

Java : How is memory usage of a program calculated by a java compiler?

I am solving this problem. It desires a memory limit of 50000bytes . So if I allocate a 2D array of int of size 1000 X 1000 , shouldn't it exceed the memory bounds ?

PS : I saw this solution to the problem and the programmer has allocated a 2D array of size m X m . And if m is equal to 1000, then I think the memory bound will be exceeded. But codechef has accepted his solution.

Is there a faulty mechanism of codechef compiler or am I missing something?

Upvotes: 3

Views: 198

Answers (2)

Lavish Kothari
Lavish Kothari

Reputation: 2321

50000 bytes is the maximum size that your source code can have, it is not at all related to the memory that your program uses. The 2D array of size 1000*1000 will be allocated to your program from the RAM (Primary memory).

By the way on cadechef, limits for maximum size of a single array is around 10^7 to 10^8 as it is very difficult to allot contiguous memory locations.

You can refer to this discussion on codechef for further details.

Upvotes: 0

NPE
NPE

Reputation: 500157

From the site:

Source Limit: 50000 Bytes

This limit applies to the size of your source code, not to the amount of memory the program allocates. The two are completely unrelated.

Upvotes: 3

Related Questions