From owner-freebsd-chat@FreeBSD.ORG Fri Nov 16 06:10:43 2007 Return-Path: Delivered-To: freebsd-chat@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 29FBB16A41A for ; Fri, 16 Nov 2007 06:10:43 +0000 (UTC) (envelope-from deeptech71@gmail.com) Received: from nf-out-0910.google.com (nf-out-0910.google.com [64.233.182.191]) by mx1.freebsd.org (Postfix) with ESMTP id B8CA213C459 for ; Fri, 16 Nov 2007 06:10:41 +0000 (UTC) (envelope-from deeptech71@gmail.com) Received: by nf-out-0910.google.com with SMTP id b2so719357nfb for ; Thu, 15 Nov 2007 22:10:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:user-agent:mime-version:to:subject:content-type:content-transfer-encoding; bh=HsYtoH8+Xn69Hcy8yo2340DobQ15+82JUwaI3Tp/tjE=; b=W6eIemDv3nov4SxUMgpVyBEG7UltpnZBBejpHTC0viniAsqZdXdNTR2XlfRvnzlkS5GogXgYBhcW1CreFgsmc9+zyIfo4U7DHFitKX8ss5xYYSxkLM/ezDULUuiYb/gCxYw5Ybp6iwgmCqAbSOEGqqKkfOoBXlb3g2YOTY9sUhM= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:user-agent:mime-version:to:subject:content-type:content-transfer-encoding; b=e8n9qTRZO4mOeA1z9GP/sp5kGXoQa6fdWNN7Th2mVvy3QAONnW7QX/5IhScIn5ugU191Ha5ny/va/YRcOtYwYHHS4yzM9l1u4OtFxCRHJZdrym/Do6F0dlN43NFQeKEbMM+cAPcVyNbzECkYkrzjWrLc1P4QVR9aBH9emHb59Fw= Received: by 10.86.54.3 with SMTP id c3mr1422983fga.1195193433440; Thu, 15 Nov 2007 22:10:33 -0800 (PST) Received: from ?192.168.123.1? ( [84.0.108.178]) by mx.google.com with ESMTPS id l19sm2573040fgb.2007.11.15.22.10.32 (version=SSLv3 cipher=RC4-MD5); Thu, 15 Nov 2007 22:10:32 -0800 (PST) Message-ID: <473D344C.1080805@gmail.com> Date: Fri, 16 Nov 2007 07:10:20 +0100 From: deeptech71@gmail.com User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.8) Gecko/20071009 SeaMonkey/1.1.5 MIME-Version: 1.0 To: freebsd-chat@freebsd.org Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: C out-of-bound pointer question X-BeenThere: freebsd-chat@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Non technical items related to the community List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 16 Nov 2007 06:10:43 -0000 int x[N]; Values in x[] are (rand()%10)+268435410, aka 268435410..268435419. The algorith counts each individual value. // v1.0 uses if( x[n] == ___ )'s // v2.0: int k[268435420] = {0}; // k uses almost 1GB of memory for (n = 0; n < N; n++) { k[ x[n] ]++; } // v2.1: int k[10] = {0}; int* p = k-268435410; for (n = 0; n < N; n++) { p[ x[n] ]++; } The values in x[] are guaranteed, so k[ x[n]-268435410 ] are k[0] to k[9], but is *((k-268435410)+26843541_) safe? (as long as I do no dereference such out-of-bound memory region)