| |
| |
| |
|
Page: 1 2 3 4
Comments:
<0> Also, I need a smack for 'null' too. <1> Yeah. I mean, null instead of nullptr? What craziness is that. <0> haha <2> hey when reallocation memory with new or realloc keep the old datas <2> or it remove them <2> ? <0> realloc is such a piece of **** <1> You can't reallocate with new, and realloc shouldn't be used. <0> realloc wouldn't work with objects for one. <2> ok <0> You could duplicate it with the placement new, but most often than not, that's a "WHAMG HACK" sign. <2> than what to do if i wannaextend the size of the momery i allocated with new <2> ? <0> Guest68442, Delete it and create a larger chunk? <3> Guns|n|r0s3s_: guess :) <2> copying
<2> and so on ? <3> pretty much <0> Or rather, create a larger chunk, copy and delete. <2> aint there a tricky way <2> like <2> redim <2> redim preserve of VB <0> You could use realloc as an optimization AFTER you figure out that part of your code is crucial to be fast. <0> If you're dealing with primitives. <1> I really wouldn't. <2> ok <4> ? <0> Yeah, realloc might end up copying anyway. <2> my spontain solution was <0> Well, it's likely to. <2> a = new datatype[n] <2> b=new datatype[n+x] <2> a=b <2> or no <2> delete []a ;then a=b <2> is that the way ? <1> You forgot the copying the data step, but yeah. <2> ah ya <1> std::copy(a, a+n, b) <2> and the copy data step <2> can be for thousand <2> s <0> Then you might need something else to store your data. <2> u mean STL <2> ? <0> If you insert more than access by index, you might consider a linked list. <5> If you just add at the end, a deque might do the job. <0> yea <4> hmm.... map... <4> :-P <2> well i have to make an ID destribution cl*** <4> they all have their uses <0> Sure <2> and sometime some ids are not used anmore <4> perhaps a hashmap, or was it just a hash cl***, cant remember now <4> perhaps i'm just making it up :-P <2> so store them in an array to give them back <2> i think for that a deque qill be fine <5> If you are removing stuff from the middle, you might be better off with a list. <6> arse <2> well i remove the first availble id <4> rhw: wb :-P <5> Sounds more like a deque then. <7> use a freelist <2> can i use using namespace std; inside another namespace ? <7> rather than explicitly testing for one that is free <0> Of course you can <0> but you don't want to <2> why ? <5> In fact, you almost never want to do a using namespace std; :-) <2> well <2> i try to avoid that <0> Just do using std::vector; using std::whateverYouWant; <2> ahh <0> The std namespace is huge. You don't need all of it. Just parts.
<5> using std::protection; <2> and i use only what i need <2> cool <2> i didnt know that <2> lol <0> Even though I usually don't do that either, because I like it to be obvious whenever I use something from the std. <7> nah using namespace std; is great <7> if (blah) { using namespace std; something_cute; } <0> jdavis, That's a bit different than namespace jdavis { using namespace std; //........ <1> jdavis: That saves you typing when? <7> well perhaps not in a case like that, but on occasion there have been functions where there is heavy use of the stl <1> ...and, arguably, "namespace gnr { using namespace whoops; }" is better than "namespace rhw { using whoops::a_daisy; }" because you can write rhw::a_daisy but not gnr::a_daisy. <1> ...but you're right, using directives are crappy. <7> why I like them <1> rhaaw: [14:54] <@Rethguals> ...and, arguably, "namespace gnr { using namespace whoops; }" is better than "namespace rhw { using whoops::a_daisy; }" because you can write rhw::a_daisy but not gnr::a_daisy. <3> just don't "use" std::string <1> tequilla, you have a better alternative? <7> I think std::string is ok <3> if I'm doing just string manipulation (not for use with containers)...? const char* ? <1> Why take on memory management? <7> tequilla, things like string.find. <7> find_first_of() save lots of time <1> Apart from not being as useful as you'd like, how does std::string get in your way? <1> jdavis: You should have seen the example the other night. <3> only the former: I think my pointer code that deals with C strings looks nicer <7> Rethguals, someone tried to not use it? <3> the pos = std::find_if(s.begin() + pos, s.end(), std::not1(std::ptr_fun(&::islower)))- s.begin() ? :) <1> jdavis, no. The string functions don't accept a predicate, so are tedious to use. <1> Yeah. <1> ...except that you then need a "if (pos == s.size()) pos = std::string::npos;" :) <3> yep <3> before the - s.begin() <3> actually, no, I'm thinking about comparing an iterator against s.end() <1> No, after. <1> That would be better. <1> ...but whatever. The string methods don't mix well with the standard algorithms. <3> i = std::find_if(...); pos = (i != s.end()) ? (i - s.begin()) : std::string::npos; or similar <1> I think taking on memory management is daft. <3> and I can't exactly loop on while (islower(s[pos])) ++pos; because there's no guarantee that s[s.size()] == 0 <1> All the nice logarithmic allocation, exception safe deallocation, etc... gone. <1> tequilla, you could go through c_str, and that would hold. <3> in the above scanner, the only allocation occurs once (in the constructor): yeah, I ended up constructing the std::string and using .c_str() - but the scanning code involved no algorithms or string methods at all <7> what is it you're doing with this, tequilla <3> jdavis: scanner and parser for some odd grammar, nothing important or useful <7> to learn? <1> Should probably be using streambuf_iterator :) <3> jdavis: well - it has use to person I'm writing it for; ironically, I had treated it as an exercise to get myself to use basic_string and the standard library algorithms more :P <7> grammars can be one tough cookie <1> Sigh. I hate buying clothes. BBL. <8> oh yes.. buying clothes.. such a travesty <1> I should have someone to do it for me! <8> $1000 and i'll do it <1> I need something clean to wear for a conference I'm going to tomorrow. <8> i'll find you a nice tight hot-pink polo with white shorts and a white scarf :D <2> how to declare a static variable in a header and make static for all the modules including that header ? <2> can i put a constructor in a struct ? <5> Yes. <2> and fuctions ? <2> functions ? <2> converstion operators ? <5> A struct is just like a cl***, except things are public by default instead of private. <2> okay <2> thanks <2> how to look for value in a list ? <2> find , seek ?? <0> Guns|n|r0s3s_, Look into the extern keyword, but please beware that if you have more than one static variable, the standard does not define any rules regarding the order which they get constructed (a problem when dealing with multiple static variables and static functions). <2> or i have to scroll ir <2> it <0> erm <0> I had the text scrolled up.
Return to
#c++ or Go to some related
logs:
#chat-world #kl bornova ahra yay turkye teseo2 Deepa Nayak
arabik chat
#worldchat katspaw #chat-world
|
|