ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Common Board

Buggy Memory Limit
Posted by Vinicius Fortuna 3 Oct 2001 03:21
The way of checking the memory limit has bugs!
I've written a program with an array of ints and I've got a
certain amount of memory.
Than I only changed the array type to short int and the use
of memory increased!
How can it be?
More...
Posted by Vinicius Fortuna 3 Oct 2001 03:27
Now I've just declared the array (which was global) local
and it used less memory!!!!
Re: More...
Posted by Algorist 4 Oct 2001 02:22
> Now I've just declared the array (which was global) local
> and it used less memory!!!!
>

Well, I'm nut sure, but I think the compiler uses "smart
compiling" which is that it allocates memory for a variable
if and only if it has been used. For example, if you use an
extremely large array of bye, but you are on a test that
uses only the first 50 elelments, you'll get 50 bytes. The
next test will use more elements- for example 1000 bytes.
And the array is 10000 bytes in both case according to your
calculations.

I'm not sure about that. The admin should answer
Re: Buggy Memory Limit
Posted by Marat Bakirov 6 Oct 2001 04:15
<h1><a name="_langref_data_type_ranges"></a>Data Type
Ranges</h1>
<p>
C/C++ recognizes the types shown in the table below.</p>
<table border=1 cellpadding=5 cols=4 frame=below rules=rows>
<tr valign=top>
<td class=label width=21%>Type Name</td>
<td class=label width=13%>Bytes</td>
<td class=label width=25%>Other Names</td>
<td class=label width=41%>Range of Values</td>
</tr>
<tr valign=top>
<td width=21%>int</td>
<td width=13%>*</td>
<td width=25%>signed, <br>
signed int</td>
<td width=41%>System dependent</td>
</tr>
<tr valign=top>
<td width=21%>unsigned int</td>
<td width=13%>*</td>
<td width=25%>unsigned</td>
<td width=41%>System dependent</td>
</tr>
<tr valign=top>
<td width=21%>__int8</td>
<td width=13%>1</td>
<td width=25%>char, <br>
signed char</td>
<td width=41%>&#8211;128 to 127</td>
</tr>
<tr valign=top>
<td width=21%>__int16</td>
<td width=13%>2</td>
<td width=25%>short, <br>
short int, <br>
signed short int</td>
<td width=41%>&#8211;32,768 to 32,767</td>
</tr>
<tr valign=top>
<td width=21%>__int32</td>
<td width=13%>4</td>
<td width=25%>signed, <br>
signed int</td>
<td width=41%>&#8211;2,147,483,648 to 2,147,483,647</td>
</tr>
<tr valign=top>
<td width=21%>__int64</td>
<td width=13%>8</td>
<td width=25%>none</td>
<td width=41%>&#8211;9,223,372,036,854,775,808 to
9,223,372,036,854,775,807</td>
</tr>
<tr valign=top>
<td width=21%>char</td>
<td width=13%>1</td>
<td width=25%>signed char</td>
<td width=41%>&#8211;128 to 127</td>
</tr>
<tr valign=top>
<td width=21%>unsigned char</td>
<td width=13%>1</td>
<td width=25%>none</td>
<td width=41%>0 to 255</td>
</tr>
<tr valign=top>
<td width=21%>short</td>
<td width=13%>2</td>
<td width=25%>short int, <br>
signed short int</td>
<td width=41%>&#8211;32,768 to 32,767</td>
</tr>
<tr valign=top>
<td width=21%>unsigned short</td>
<td width=13%>2</td>
<td width=25%>unsigned short int</td>
<td width=41%>0 to 65,535</td>
</tr>
<tr valign=top>
<td width=21%>long</td>
<td width=13%>
Re: Buggy Memory Limit
Posted by Marat Bakirov 6 Oct 2001 04:16
Sorry, I forgot thatt HTML is prohibited :)

As far as I know , int is the same as long here (4bytes)
while short is 2 bytes.

from MSDN:

Data Type Ranges
C/C++ recognizes the types shown in the table below.

Type Name Bytes Other Names Range of Values
int * signed,
signed int System dependent
unsigned int * unsigned System dependent
__int8 1 char,
signed char &#8211;128 to 127
__int16 2 short,
short int,
signed short int &#8211;32,768 to 32,767
__int32 4 signed,
signed int &#8211;2,147,483,648 to 2,147,483,647
__int64 8 none &#8211;9,223,372,036,854,775,808 to
9,223,372,036,854,775,807
char 1 signed char &#8211;128 to 127
unsigned char 1 none 0 to 255
short 2 short int,
signed short int &#8211;32,768 to 32,767
unsigned short 2 unsigned short int 0 to 65,535
long 4 long int,
signed long int &#8211;2,147,483,648 to 2,147,483,647
unsigned long 4 unsigned long int 0 to 4,294,967,295
enum * none Same as int
float 4 none 3.4E +/- 38 (7 digits)
double 8 none 1.7E +/- 308 (15 digits)
long double 10 none 1.2E +/- 4932 (19 digits)


The long double data type (80-bit, 10-byte precision) is
mapped directly to double (64-bit, 8- byte precision) in
Windows NT and Windows 95.

Signed and unsigned are modifiers that can be used with any
integral type. The char type is signed by default, but you
can specify /J to make it unsigned by default.

The int and unsigned int types have the size of the system
word. This is two bytes (the same as short and unsigned
short) in MS-DOS and 16-bit versions of Windows, and 4
bytes in 32-bit operating systems. However, portable code
should not depend on the size of int.

Microsoft C/C++ also features support for sized integer
types. See __int8, __int16, __int32, __int64 for more
information. Also seeInteger Limits.


------------------------------------------------------------
--------------------
Re: Buggy Memory Limit
Posted by Vinicius Fortuna 9 Oct 2001 21:28
You're right!
That's why the use use short ints should decrease, and not
increase, the amount of memory used!