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

Pages: 1-

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:07

1. I believe it's constant.
2. Yes, but you can just call memberFunction(); directly.
3. NO U

Also, sage for C++.

Name: Anonymous 2008-09-26 9:09

Self sage for answered questions. Thankyou kind anon.

Name: HMA 2008-09-26 9:13

1. A string is essentially an array of characters. Think about it. Also, premature optimization for anything but terribly long strings that you won't be using.
2. Yes, and you could even access attributes via this->attr = 1234. Try to name your methods with verbs, btw, cat::number sounds a lot more like an ID variable or something.
3. Done.

Name: Anonymous 2008-09-26 9:31

1. Here's a nickel, get yourself a compiler that hoists loop invariants.

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.

Name: Anonymous 2008-09-26 10:16

1. It's O(1), if you're talking about std::string.
2. Yes, but it's not really necessary and in most cases doesn't add much that can't be inferred. I'd use it only in cases where confusion might arise.

Watch out for std::list::size(), by the way. The standard specifies that one of size() and splice() is O(1), but it doesn't specify which. So, in reality, you have to treat them both as O(N), although usually it's size(). Pig disgusting.

Name: HMA 2008-09-26 10:58

>>6
Yeah, I also code for ATMegas with 1KB of RAM, but I don't use std (or strings for the matter). I can see where you're going, though. So far I've had a good time using templated classes to minimize RAM use for everything that's known at compile-time. Also don't forget to use 8-bit ints (uint8_t for AVR-libc) when you can instead of int, it's 16-bits by default so it requires twice as many cycles to process (plus the memory) - I know your snippet is probably not for an AVR, but just in case.

Name: Anonymous 2008-09-26 11:43

>>8

Yeah, i'm beginning with Arduino (arduino.cc) which is an io board with an embedded ATMega 16-8. Arduino is programmed with Wiring, which is a C++ type language with built in handling for digital and analog IO. I'm mostly being careful with what I do by trying to keep as much of everything into bytes, which as you say, are 1 cycle ops. So I don't have a problem

I've slowly come to realise that the second question I asked in OP was mainly a huge brainfart; I should have just been calling memberFunc(), without bothering with a self reference. It was for my first year comp-sci courses really. Programming for microcontrollers has just got me in a mindset where i'm conscious of my resource use.

Doing physical computing stuff is fun though. Being able to get a PWM servo driver up and running in under an hour is really satisfying.

Name: Anonymous 2008-09-26 12:27

Microcontrollers? And you're using the STL?

ಠ_ಠ

Name: Anonymous 2008-09-26 13:46

>>8
Try an 8052 sometimes. It's fun!

Name: Anonymous 2008-09-26 14:26

>>10
STL is hueg and I can't understand it!
Java is pig slow!
Leah Culver doesn't have acne!
etc!

Name: Anonymous 2008-09-26 14:39

>>12
I've never written code for anything other than the x86_64 platform!!

Name: Anonymous 2008-09-26 22:13

>>12
STL is not hueg, it's ugly.

Java is not pig slow, it's pig disgusting.

Leah Culver is hotter than any woman you're ever going to fuck.

Name: Anonymous 2008-09-27 1:46

STL is not hueg,
Java is not pig slow,
lies.

Name: Anonymous 2008-09-28 10:56

Java

Name: Anonymous 2009-03-06 9:44

The variants etc etc   etc Fucking truth?

Name: Anonymous 2011-02-02 23:10


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