Memory use for int, long, etc

I have to load some 400,000 (perhaps upto 1,200,000) numbers in memory,
none of them larger than 100. I am looking for ways to reduce the
memory load.

If I store each as an int, would i use 400,000 bytes of physical mem?

If I store four numbers per long, would i use 100,000 bytes of physical
mem?

In other words, what is the most efficient of storing the lot?

Appreciated.

0
the44secs (141)
8/7/2006 2:43:17 AM
vc.mfc 33608 articles. 0 followers. Follow

7 Replies
579 Views

Similar Articles

[PageSpeed] 24

Alexander wrote:
> I have to load some 400,000 (perhaps upto 1,200,000) numbers in memory,
> none of them larger than 100. I am looking for ways to reduce the
> memory load.
> 
> If I store each as an int, would i use 400,000 bytes of physical mem?
> 
> If I store four numbers per long, would i use 100,000 bytes of physical
> mem?
> 
> In other words, what is the most efficient of storing the lot?
> 
> Appreciated.
> 

400,000 ints would use 1,600,000 bytes of memory.  Same if you use long.

The most efficient size would be with char or unsigned char.

-- 
Scott McPhillips [VC++ MVP]

0
Scott
8/7/2006 5:29:05 AM
On 6 Aug 2006 19:43:17 -0700, "Alexander" <the44secs@yahoo.com> wrote:

>I have to load some 400,000 (perhaps upto 1,200,000) numbers in memory,
>none of them larger than 100. I am looking for ways to reduce the
>memory load.
>
>If I store each as an int, would i use 400,000 bytes of physical mem?

You would use 400,000 * sizeof(int) bytes, which is 1,600,000 bytes for
VC's 32 bit int.

>If I store four numbers per long, would i use 100,000 bytes of physical
>mem?

No, you'd need 400,000 bytes, or 100,000 longs, for VC's 32 bit long.

>In other words, what is the most efficient of storing the lot?

Numbers < 100 will fit in a char, so use an array of char. Actually, you
should use std::vector<char>, or I think MFC provides CByteArray if you
want to stick with MFC.

-- 
Doug Harrison
Visual C++ MVP
0
dsh (2498)
8/7/2006 5:40:27 AM
Thank you both.

0
the44secs (141)
8/7/2006 8:52:30 AM
sizeof(int) == 4  so 400,000 int values would use 400,000*sizeof(int) bytes.

since no value would exceed 100, this is a place you could reasonably use 'char' as your
datatype. It can hold values from -128 to +127, or you could use unsinged char (aka BYTE)
which holds values from 0 to 255.

There would be no need to store 4 values per int since using char/BYTE gives you the
desired effect.

I'm curious why you think 1,200,000 is a "large" number.  Storing these as int values
would use 0.2% of your available address space; it would be 0.8% of the physical address
space of a 512MB machine.  These are small numbers.

Stored as int values, these would require 1171 pages; stored as char values, these would
require 292 pages; a 512MB computer has 131,072 pages available in physical memory.

If you're really fanatic, note that you could use polynomial packing where you use modular
arithmetic to pack and extract, but there is little point to doing this for such a minute
amount of data.  Just use char/BYTE.
					joe
On 6 Aug 2006 19:43:17 -0700, "Alexander" <the44secs@yahoo.com> wrote:

>I have to load some 400,000 (perhaps upto 1,200,000) numbers in memory,
>none of them larger than 100. I am looking for ways to reduce the
>memory load.
>
>If I store each as an int, would i use 400,000 bytes of physical mem?
>
>If I store four numbers per long, would i use 100,000 bytes of physical
>mem?
>
>In other words, what is the most efficient of storing the lot?
>
>Appreciated.
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15975)
8/7/2006 4:25:06 PM
Thank you for the reply, Joe.

The reason why I consider the amount of numbers "large" is not actually
due to the amount itself but because I need to loop through them
sequentially many times over performing certain calculations. On the
whole, time consuming.

I am still considering the options really. What I am after ultimately
is a fast string matching algorithm that would yield a set of alikes to
a pattern. A sort of spell checker but restricted to orthographic
distance measures (meaning no soundex/metaphone/phonetic keys).
Something along the lines of Ukkonen's. Speed and relatively flexible
matching are the bottom line.

0
the44secs (141)
8/7/2006 6:59:03 PM
Note that the way caches work, you will get performance improvements by taking advantage
of knowledge of how caches work (usually an order of magnitude).  Note that on the whole
it takes as long to fetch a byte as a DWORD (1 clock cycle on a Xeon) and the change from
4 bytes to 1 byte gives only a factor of 4 at best, and I suspect a factor of 1 typically.

Fast string matching: you need to look at Boyer-Moore and algorithms in that class. Beyond
that, you need to worry more about architectural issues and less about sizes.

Note that anything that does spell checking needs to work with the full 0..255 character
set, and probably work with Unicode if you're serious.  So values in the range 0..100
wouldn't be sufficient for representing accented characters and the like.  Unless you're
talking about doing case-folding and various forms of compression to get your range, you
don't really have enough values, and the conversion is going to cost you a lot of time
also.
				joe

On 7 Aug 2006 11:59:03 -0700, "Alexander" <the44secs@yahoo.com> wrote:

>Thank you for the reply, Joe.
>
>The reason why I consider the amount of numbers "large" is not actually
>due to the amount itself but because I need to loop through them
>sequentially many times over performing certain calculations. On the
>whole, time consuming.
>
>I am still considering the options really. What I am after ultimately
>is a fast string matching algorithm that would yield a set of alikes to
>a pattern. A sort of spell checker but restricted to orthographic
>distance measures (meaning no soundex/metaphone/phonetic keys).
>Something along the lines of Ukkonen's. Speed and relatively flexible
>matching are the bottom line.
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15975)
8/8/2006 4:00:00 AM
I'll follow the leads. Thanks Joe.

0
the44secs (141)
8/8/2006 1:58:38 PM
Reply:

Similar Artilces:

Using Access form to assign values of variables in an Excel VBA program
I have created a VBA program for Ms Excel.But,to get desired results, every time, I go into the code to change the values of variables.Is there a way to get the values of variables stored in an Access table? YOu need to do a search for ADO method (ActiveX Data Object). There are plenty of example of code on the web. You need to add two references in your VBA to use the method. from VBA menu tools - References 1) Microsoft Access XX.X object library 2) Microsfot ActiveX Data Objects X.X library Use the latest versio of the two libraries on your PC. You will make a conn...

Using the SDK to update customized fields
The SDK provides references to the XSD schema that can be used for writing CREATE or UPDATE statements. How do you go about updating a custom field that you've added to an entity. Specifically, we add a field to the INCIDENT entity using the DEPLOYMENT manager etc. How can i create my XML - what's the tag that I need to use in order to update the custom field (call it testfield - CFStestfield) does the XSD get updated automatically? Is there anyway to do this?? Thanks. Nick Nick, All you need to do is add the appropriate element to the XML. In your example, it would be CFStestf...

Bar Code
I'm opening a new retail business and would like to use the Manufactures bar code on many of my items......but for the life of me I can't figure out how to load the information into my system. I've serched the HELP screens, but no answers. I'm desperate - Can anyone guide me on how to do this? Sincere, thanks to anyone who can help :) Monica If using the UPC as your ILC doesn't work, you can add the UPC codes to the Alias tab of the Item Properties. Then if you're searching for WIDGET you don't need to memorize the UPC codes. HTH, Tom "Monica" ...

Put daily use worksheets in a toolbar in Excel
Hi, I have Excel 2003 with all updates. Seems to me I used to have a custom toolbar in the menubar area with shortcuts to files I used every day - but it was a long time ago. Is there a way to do that? Thanks, Marti Just record a macro that opens 'em, Marti. See: http://www.officearticles.com/excel/record_a_macro_in_microsoft_excel.htm ************ Anne Troy www.OfficeArticles.com "Marti" <MartiB@hotmail.com> wrote in message news:erghi19qjuba0d28jqkic1h5uou3b9uj0n@4ax.com... > Hi, > I have Excel 2003 with all updates. Seems to me I used to have a > custom t...

Toolbar buttons (text and bitmaps) are disappearing, when using with MFC CToolBar class
Guys, help me to sovle the following problem I have a MFC SDI application (Vc++ 6.0) ( 2 Threads, UI and data acqusition thread). The UI is having a simple toolbar control with text and bitmap. The problem is once i run this application after doing some gui operation (like invoking some dialog box changing to diffrent view) the toolbar button is getting disappeared. sometimes the fonts of the toolbar button is getting changed or sometimes when i move the mouse over the toolbar, the buttons is slowly going away( only back ground color of rebar is comming. Is there any methods to debug this ki...

Using Popups to select a range of cells.
Hi All I have a small request for help with code. I need a macro to have popups request the first and last cells in a range , and then to select them. Can someone help? Sub test() Dim Rng As Range On Error Resume Next Set Rng = Application.InputBox("Select your range", _ "Mousework", Type:=8) On Error GoTo 0 If Rng Is Nothing Then Exit Sub MsgBox Rng.Address End Sub HTH. Best wishes Harald "Colin Hayes" <Colin@chayes.demon.co.uk> wrote in message news:8mYkILA1YlvLFw7Z@chayes.demon.co.uk... > > Hi All > >...

Using Outlook Address Book vice Windows address book
When I right click on an item as select sent to mail receipient it uses my windows address book, vice my Outlook address book. Since I don't want to update both how do I make it default to the Outlook book and contacts? -- Jeff Mu�iz Work is victory. - Ralph Waldo Emerson Open Internet Explorer and select Tools | Internet Options | Programs tab. Set the contact list dropdown to Microsoft Outlook. "Jeff Mu�iz" <jmuniz6@cox.net> wrote in message news:wEUId.20390$B95.3864@lakeread02... > When I right click on an item as select sent to mail receipient it uses my ...

SQL Smartlist uses?
Hi, I am not a GP user but I need to use SQL to retrieve information from it. The information is in a smart list my client created. I used the smartlist builder to find each table & view used to create the data set. I tried to mirror the joins the smartlist builder uses but I don't get the entire data set. The smartlist returns data for 2007 but my query returns data up to 12/31/2006. How can I get the same results the smartlist yields from SQL? Thanks, Ivan Ivan, If this query is against the GL, from what you're saying, it sounds like 2006 has been closed, and 2007 is open...

DO NOT DO UPDATE IF YOU USE BESTBUY OR DELL!!!!
Once you do the update those banks dont show up as available for linking and auto downloads. If anyone knows how to fix this let me know. Bryan It is the choice of the card issuer not to upgrade with Money. Money did not make this decision. cindy "Bastards" <cellphonesebay@gmail.com> wrote in message news:1185226618.281667.320890@k79g2000hse.googlegroups.com... > Once you do the update those banks dont show up as available for > linking and auto downloads. If anyone knows how to fix this let me > know. > > Bryan > On Jul 23, 5:51 pm, "Cindy C...

How do I use Outlook 2003 with the Win2003 built-in POP3 server?
I am running a small network using Win2003 R2 servers and XP Pro workstations. I do not have Exchange and use the built-in POP3 server for email. I am using Outlook 2007 on the workstations to retrieve mail, but my users need to roam. All my users' data is redirected to an NFS share on my servers and I have relocated their pst files to their home folders. This seems to work OK, except for one user. In this case, when she opens Outlook, she gets the initial setup condition and we need to re-enter all her data again. The pst file seems to be intact and her mail is not lost. I h...

using multiple conditions
I would like to know how to write the syntax to test for 1. age>44 or 2. Seniority is >9 and by determining the answer to that 3. Arsenic exposure >4.9 4. Cadmium exposure >2.4 If 1. is true or 2. true then I need to check 3. and 4. if 1. is true or 2. is true and 3 and 4 are false then ? if 1 or 2 is false and 3 or 4 is false then something else would I use and or /and condition. The way I wrote my syntax the or works but the and does not. Any clues on how to write the syntax to check for all 4 conditions? This is one solution: ="1 is "&...

Importing Excel and Word using automation
The last time I tried this I got very frustrated. I think I'll probably need to buy a book or something. Can someone recommend such a resource, or any other suitable resource for that matter? Before you go out and buy a book, try reading the Automation documentation that Microsoft provides with their Office applications. The documentation file names vary, depending on the version of Office, but for instance, my Office 2003 documentation is in files named the following (obviously, the root path varies depending on where you installed): E:\Office\OFFICE11\1033\VBAXL10.CHM E:\Office\OFF...

Using dial-up w/ citibank
Does credit card validation w/ citibank on a dial-up connection required that I get an Internet Service provider, or does the software simply call an 800 number out the modem when doing credit card authorizations? Thanks - Bob The answer depends on your configuration. I'd be happy to speak with you. I can be reached at 949-629-3002 during the day Pacific Time. Brett "Bob (new user)" wrote: > Does credit card validation w/ citibank on a dial-up connection required that > I get an Internet Service provider, or does the software simply call an 800 > number out t...

Feasibility of using visual basic express
Hi Is it possible to develop sql server db winform apps using visual basic express? Thanks Regards Yes, The easiest way, have a look to SQL to Linq success Cor "John" <info@nospam.infovis.co.uk> wrote in message news:OV8Ezd3tKHA.4908@TK2MSFTNGP06.phx.gbl... > Hi > > Is it possible to develop sql server db winform apps using visual basic > express? > > Thanks > > Regards > Thanks. Isn't Linq to SQL killed by MS? http://ayende.com/Blog/archive/2008/10/31/microsoft-kills-linq-to-sql.aspx "Cor ...

HOWTO: Bulk change "Hide from Exchange address lists" under "Exchange Advanced" using ADModify or VBScript
Using ADModify: (http://www.gotdotnet.com/workspaces/releases/viewuploads.aspx?id=f5cbbfa9-e46b-4a7a-8ed8-3e44523f32e2) 1. Select the CUSTOM tab 2. Check Box "Make a customized attribute modification" 3. Attribute Name field, enter "msExchHideFromAddressLists" (without quotes) 4. Attribute Value field, enter "TRUE" to Hide from lists, "FALSE" to show in lists (again, without quotes) 5. Hit Go! ----------------------------------------------------------------------- Using VBScript: (http://www.microsoft.com/technet/scriptcenter/resources/qanda/oct05/hey...

Fixed Assets import using Integration Manager
Hello, I am having an issue whemn importing Fixed Assets. I have a simple file that I was able to import in one environment, but not successful at another environment. The issue that I am running into is I receive this error when importing the asset using Integration Manager for version GP 10: Error: Microsoft.Dynamics.GP.eConnect: Number = 8692 Stored Procedure taCreateAssetID : Description = The UpdateIfExists parameter is set to 0 and you are attempting to integrate a record that already exists in the FA00100 table I tried manually creating one asset and then running the import ...

Using Money with an external harddrive
I would like to set up Money on a portable harddrive that will be the location of both the Microsoft Money files and my personal Money data files so that they are not kept on my business laptop. I tried this once in the past but got very frustrated and wanted to give it a try again. Just wondering if anyone has mastered this? Thanks in advance, David The data file should be easy. Setting up the application to be there will probably be a lot harder as most installers won't install on removable devices. Though Money's installer will let you specify where to install it, I'm...

Working with a spread sheet to show names, address, etc.
While working with a spread sheet to develop a roster when I have a zip code to enter that begins with a 0 such as 08842 the program refuses to show the zero and continually drops it. Is there a way to rectify this problem? Hi Betty Format your cell as text before you enter the codes (Select the cells and use Ctrl-1 and on the number tab choose text) Or type a ' before the code. -- Regards Ron de Bruin (Win XP Pro SP-1 XL2002 SP-2) www.rondebruin.nl "Betty Cea" <cea@ezlinknet.com> wrote in message news:032e01c389e7$06122910$a401280a@phx.gbl... > While work...

Using Outlook2003 in different locations with different SMTP Servers.
We use Outlook 2003 as a mail client to access email held on a pop server with no probs. One of our users though works in the office (NETWORK) and remotley abroad using a different ISP (DIAL UP) Ive set up Outlook on her laptop to send and receive from both locations using the same PST file which works fine. But when running a send receive via dial up it still checks for mail on the network connection which fails because of the different SMTP server that is required. Id like to set it so mail is only sent or received using the connection that is availaible. I tried setting up annother...

FW: Use this security pack from MS Corporation
--gsydeaoodkdrzxm Content-Type: multipart/related; boundary="lohgixbpannvck"; type="multipart/alternative" --lohgixbpannvck Content-Type: multipart/alternative; boundary="zgzowyecznv" --zgzowyecznv Content-Type: text/plain Content-Transfer-Encoding: quoted-printable Microsoft Partner this is the latest version of security update, the "September 2003, Cumulative Patch" update which eliminates all known security vulnerabilities affecting MS Internet Explorer, MS Outlook and MS Outlook Express. Install now to maintain the security of your computer from...

Use of Money for audits
Do Money users generally also keep copoies of all their bank statements? It seems redundant. On the web I get conflicting advice, even in the same article. On the one hand I'm told that software such as Money is acceptable to the IRS (strange, since you can enter your own transactions). On the other hand, the advice is to keep electronic copies of all statments. What do real life users do? I keep all the paper copies including tax return stuff and print a Money all transactions all accounts report once a year besides. It fills about one copy paper carton every second or third ...

Multicompany Smartlist Using Extender Fields
I am trying to create a Multicompany Smartlist based on additional fields I added using Extender. I can get it to work for one company but I can not get data for both company's to show on the one smartlist. Any suggestions? Thanks, Laura Laura, Not sure what you've tried, but one approach would be to create a SQL view and use it in SmartList Builder. Here is an example: http://victoriayudin.com/2008/11/08/sql-view-to-show-open-ap-invoices-from-multiple-companies-in-gp/. -- Victoria Yudin Dynamics GP MVP Flexible Solutions - home of GP Reports http://www.flex-solutions.com/g...

Sort order when using Contacts as Address Book?
When using Contacts as an Address Book, is there a way to change the sort order without changing the Default Full Name order? Currently when I select "To..." while composing a new message, Contacts are sorted by first name. I'd like to sort them by last name. Thanks. -- Lew One of the most frequently asked questions (probably becuase it's one of the most carefully hidden options): Go to Tools > E-mail accounts > View or change existing directories or address books > Outlook Address Book > Change. > Set your sort order there -- Russ Valentine [MVP-Out...

Running simple business using office
Hi, I'm a student and have begun selling some books on amazon. I wanted to develop my business process skills so see it as running a small business. I want to use office to store my 'inventory,' transactions, generate simple invoices and perform some simple analysis e.g. how much i made in a month. (I have student edition with excel and word) I want to keep one data source from which I can perform these tasks. I've got a lot of programming experience but its more from a business process perspective i'm interested. e.g. the best way to store and manipulate the data. I would ...

How many files is an IMC of Exchange using?
Hi everyone, I have an issue with my Exchange 5.5 IMC, which was added after the Exchange, its Service Pack(4), and Hotfixes were installed. I suspect there might be some files, if IMC is not just using MSEXCIMC.exe, mis-matching at version level. Could anyone who knows provide me the info in the subject line? Thanks in advance Eric What is the issue? eric z wrote: > Hi everyone, > > I have an issue with my Exchange 5.5 IMC, which was added after the > Exchange, its Service Pack(4), and Hotfixes were installed. I suspect there > might be some files, if IMC is not just...