Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

My Anus

Name: Anonymous 2008-09-26 8:56

1. Time complexity of string::size()? Can't find it anywhere. I'm trying to decide if

int size = string.size()
for(int i(0); i < size; i++)
  dostuff();

is less complex than

for(int i(0); i < string.size(); i++)
  dostuff();

If it's anything other than constant (ie. a lookup), then doing the latter is really, really bad practise.

2. Is:

this->memberFunction();

an appropriate call for an instance of a self-member in a member def? ie.

int cat::number(int a)
{
  if(a < 10)
  {
    cout << a << endl;
    this->number(a++);
  }
}

3. hax my anus

Name: Anonymous 2008-09-26 9:43

>>4

1. Ok, I've thought about it. If I want the length, I'll either keep track of the number of elements added or removed, or do a linear count of the elements, depending on my ram or time budgets. Still doesnt answer the question though. It's still either constant (a lookup) or linear (a count).

2. I realise I'm being retentive about complexity, when I'm most likely talking about very small strings, but I'm trying to practise hand-optimising my code. I started working with microcontrollers recently, and it's challenged some of my assumptions about hardware. When you only have 1024 bytes of ram, every byte counts.

3. I know, I suck at examples though. Nomenclature isn't one of my strng suits as a programmer.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List