l i n u x - u s e r s - g r o u p - o f - d a v i s
L U G O D
 
Next Meeting:
November 4: Social gathering
Next Installfest:
TBD
Latest News:
Oct. 10: LUGOD Installfests coming again soon
Page last updated:
2010 Jun 23 23:24

The following is an archive of a post made to our 'vox-tech mailing list' by one of its subscribers.

Report this post as spam:

(Enter your email address)
Re: [vox-tech] Memory addressing?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [vox-tech] Memory addressing?



On 06/23/2010 10:42 AM, timriley@appahost.com wrote:
> The reason for the discussion was Brian's intrusion detection
> implementation stored the incoming packets in a hash
> table. The key to the hash table was quite
> large -- inbound IP address, outbound IP address, inbound port, and
> outbound port. I thought to my self, on a very large implementation (say
> Google) the table could grow to a billion entries. Could a hash table
> store this amount in memory? Could you allocate an array of half the
> total memory? Could you allocate an array of a billion integers? Brian,
> on his laptop, couldn't allocate a billion integers. But he could
> allocate a billion characters (bytes). Since I thought both bytes and
> integers were words, and since I thought memory stored words
> like registers stored words, we had our discussion.

Sounds like an interesting discussion, sorry I missed it.  Kinda of 
amusing trying to handle such a hash table on a (older I assume) single 
32 bit laptop.

> The following failed to compile with an array-to-large error:
> int main( void )
> {
>       int table[ 1000000000 ];
>       return 0;
> }

Keep in mind, that's allocating on the stack, you could easily run out 
even on a 64 bit machine.  Moving the int table up before the int main 
would allocate it directly from memory.

Also I believe that requires contiguous memory, which may well be 
significantly lower than the free memory.

> The following succeeded to compile:
> int main( void )
> {
>       char table[ 1000000000 ];
>       return 0;
> }
>
> This compiles but core dumps:
> #include<stdio.h>
> int main( void )
> {
>       char table[ 1000000000 ];
>       printf( "Hello world!\n" );
> }

Keep in mind that compilers are getting smarter and I've seen problems 
with blind arrays.  Also depending on the OS they may or may not 
allocate memory that you ask for but don't initialized.  I'm not sure 
offhand if C initializes statically allocated memory like that.  So if 
you want to insure that a memory allocation (generically is working) I'd 
use the memory.  The code I used was:
#include <stdio.h>
#include <stdlib.h>

#define big 1000000000
int table[ big ];

int main( void )
{
       int i;
       for (i=0;i<big;i++)
       {
	table[i]=i/2048;
       }
       printf ("%d\n",table[123]);
       return 0;
}

_______________________________________________
vox-tech mailing list
vox-tech@lists.lugod.org
http://lists.lugod.org/mailman/listinfo/vox-tech



LinkedIn
LUGOD Group on LinkedIn
Sign up for LUGOD event announcements
Your email address:
facebook
LUGOD Group on Facebook
'Like' LUGOD on Facebook:

Hosting provided by:
Sunset Systems
Sunset Systems offers preconfigured Linux systems, remote system administration and custom software development.

LUGOD: Linux Users' Group of Davis
PO Box 2082, Davis, CA 95617
Contact Us

LUGOD is a 501(c)7 non-profit organization
based in Davis, California
and serving the Sacramento area.
"Linux" is a trademark of Linus Torvalds.

Sponsored in part by:
EDGE Tech Corp.
For donating some give-aways for our meetings.