Main Page   Compound List   File List   Compound Members   File Members  

guess_mem.c

Go to the documentation of this file.
00001 
00002 /*=====================================================================
00003                 =======   COPYRIGHT NOTICE   =======
00004 Copyright (C) 1996, Carnegie Mellon University, Cambridge University,
00005 Ronald Rosenfeld and Philip Clarkson.
00006 
00007 All rights reserved.
00008 
00009 This software is made available for research purposes only.  It may be
00010 redistributed freely for this purpose, in full or in part, provided
00011 that this entire copyright notice is included on any copies of this
00012 software and applications and derivations thereof.
00013 
00014 This software is provided on an "as is" basis, without warranty of any
00015 kind, either expressed or implied, as to any matter including, but not
00016 limited to warranty of fitness of purpose, or merchantability, or
00017 results obtained from use of this software.
00018 ======================================================================*/
00019 
00024 /* Rewritten 6 May 1997. No longer try to guess based on filesize and
00025 cutoffs. Merely allocate an equal amount of memory to each of the
00026 tables for 2,3,...,n-grams. Total memory allocation should equal
00027 STD_MEM. This is far from optimal, but is at least robust. */
00028 
00029 #include <stdio.h>
00030 #include "toolkit.h"
00031 #include "ngram.h"
00032 #include "rr_libs/general.h"
00033 #include "pc_libs/pc_general.h"
00034 
00035 void guess_mem(int total_mem,
00036                int middle_size,   /* Size of 2,3,(n-1)-gram records */
00037                int end_size,      /* Size of n-gram record */
00038                int n,
00039                table_size_t *table_sizes,
00040                int verbosity) {
00041 
00042 
00043 
00044   int *num_kgrams;
00045   int i;
00046 
00047   num_kgrams = (int *) rr_malloc(sizeof(int)*(n-1));
00048   
00049   /* First decide on file size (making allowances for compressed files) */
00050 
00051   for (i=0;i<=n-3;i++) {
00052 
00053     num_kgrams[i] = total_mem*1000000/(middle_size*(n-1));
00054 
00055   }
00056 
00057   num_kgrams[n-2] = total_mem*1000000/(end_size*(n-1));
00058 
00059   for (i=0;i<=n-2;i++) {
00060     table_sizes[i+1] = num_kgrams[i];
00061     pc_message(verbosity,2,"Allocated space for %d %d-grams.\n",
00062                table_sizes[i+1],i+2);
00063   }
00064   
00065   
00066 
00067 }
00068 
00069 

Generated on Tue Dec 21 13:54:45 2004 by doxygen1.2.18