efficiency

Should I use #defines or enums for commands over network?

I have to transfer some values to be used as commands over the network, and I wish to make it as efficient and robust as possible, i.e. I need opinions on what to use for these commands, #defines or enums? The range of commands shall not be more than 20 commands(lets say 40 with every defined response to the command), so according to mo...

Efficiency of c++ built ins.

I am fairly new to C++, having much more C experience. I am writing a program that will use the string class, and began to wonder about the efficiency of the "length()" method. I realized though that I didn't have a good answer to this question, and so was wondering if the answer to this and similar questions exist somewhere. While I a...

Memory-efficient C++ strings (interning, ropes, copy-on-write, etc)

My application is having memory problems, including copying lots of strings about, using the same strings as keys in lots of hashtables, etc. I'm looking for a base class for my strings that makes this very efficient. I'm hoping for: String interning (multiple strings of the same value use the same memory), copy-on-write (I think this...

Why is multiplying cheaper than dividing?

I recently wrote a Vector 3 class, and I submitted my normalize() function for reviewal to a friend. He said it was good, but that I should multiply by the reciprocal where possible because "multiplying is cheaper than dividing" in CPU time. My question simply is, why is that? ...

Any ideas why QHash and QMap return const T instead of const T& ?

Unlike std::map and std::hash_map, corresponding versions in Qt do not bother to return a reference. Isn't it quite inefficient, if I build a hash for quite bulky class? EDIT especially since there is a separate method value(), which could then return it by value. ...

Does enumerating a BitArray cause lots of boxing/unboxing?

System.BitArray only implements the non-generic IEnumerable, which returns an Object for the IEnumerator.Current property. Does running a foreach over a BitArray - eg foreach (bool b in bitArray) { // ... } box and unbox each and every bit value? Looking at the bitarray enumerator in reflector, it looks like it does a fresh bitma...

Setting up a web interface to http proxies?

I want a way to allow users to go through my http proxy server (Squid, Privoxy, etc.) without having to type the IP/port in web browser settings. I was hoping I could use a simple web interface. I'm envisioning this: User goes to a website on my server (http://proxy.com) and types a URL into the form. The user's browser URL ...

clearing a small integer array: memset vs. for loop

There are two ways to zero out an integer/float array: memset(array, 0, sizeof(int)*arraysize); or: for (int i=0; i <arraysize; ++i) array[i]=0; obviously, memset is faster for large arraysize. However, at what point is the overhead of memset actually larger than the overhead of the for loop? For example, for an array of size 5...

MySQL Query: Displaying counts for many groups with many records

I need to produce a large HTML table with quarterly counts for several (around 50) different groups (jurisdictions). I have a MySQL table with around 16,000 rows which have 'jurisdiction_id' and 'quarter' fields. Unfortunately my client doesn't want the resulting report to be paginated. How would I construct a good MySQL query from which...

Fat Domain Models => Inefficient?

Looking at DDD, we abstract the database into the various models which we operate on and look at it as a repository where our models live. Then we add the Data Layers and the Service/Business layers on top of it. My question is, in doing so, are we creating inefficiencies in data transfer by building fat models? For example, say we ha...

insertAt in F# simpler and/or better

I would like to start some questions about simplifying different expressions in F#. Anyone have ideas for better and/or simpler implementation of insertAt (parameters could be reordered, too). Lists or Sequences could be used. Here is some start implementation: let insertAt x xs n = Seq.concat [Seq.take n xs; seq [x]; Seq.skip n xs] ...

Most efficient php if structure

What runs faster? Setting a default value and changing it- $foo = ""; if($bar) { $foo = "someValue"; } Or- if($bar) { $foo = "someValue"; } else { $foo = ""; } ...

Joining and searching multiple MySQL tables with one-to-many relationships

I've been furiously googling trying to figure this out, with surprisingly little luck; I would guess this is a common issue. I have 5 tables: orders, addresses, notes, transactions, line_items, and shipments. transactions, addresses and notes all have indexed order_id fields - line_items and shipments have indexed transaction_id fields...

How can I make this javascript more efficient?

Hi, i am receiving a piece of plain html from an ajax request. <h1>Title</h1> <div> content </div> This is the most simple form. Every piece contains a <h1> tag for a title, and a <div> tag containing the content. I have a nicely formatted container in the html page which needs to populate with the returned html snippet. This is t...

Building Breadcrumbs in MySQL

I have a table that defines the possible categories in my website - fields look something like this: - id - name - parentID The information is stored something like this: +-----+------+----------+ | id | name | parentID | +-----+------+----------+ | 1 | pets | 0 | +-----+------+----------+ | 2 | cats | 1 | ...

Light weight text/code editor that can open .SLN, and .CSProj Files

I'm using a weak computer that's chokes when I open too many programs (Out of my control). So I want to have a lighter way to open Visual Studio solution files and csproj files. I sometimes like to keep projects open for code reference easy access to files I care about. edit my custom msbuild tasks (don't compile thru the I...

Bit setting and code readability

I have an Arduino application (well actually a library) that has a number of status flags in it - and originally I simply declared them as ints (well uint8_t so 8 bit unsigned chars in this case). But I could have combined them all into one integer and used bitmask operations to set and test the status. An example of the former: if (_s...

What is the optimal length for an email address in a database?

I am doing my first database project. I have had the following query in the column of EMAIL_ADDRESS ... EMAIL_ADDRESS CHARACTER VARYING(20) NOT NULL, ... However, John Saunders uses VARYING(256). This suggests me that I have not necessarily understood the VARYING correctly. I understand it such that the le...

Data Structure to store billions of integers

What is the best data structure to store the million/billions of records (assume a record contain a name and integer) in memory(RAM). Best in terms of - minimum search time(1st priority), and memory efficient (2nd priority)? Is it patricia tree? any other better than this? The search key is integer (say a 32 bit random integer). And all...

Eficient logging of stdin with rsyslog

Hello, Our environment: CentOS 5, which comes with Apache 2.2 and rsyslog 2.0.6 In order to send Apache 2.2 error log we followed instructions found on the here: http://wiki.rsyslog.com/index.php/Working_Apache_and_Rsyslog_configuration It works, but the included perl script is very inefficient - it takes huge part of the system resou...