@# Quotes DB     useful, funny, interesting





Google
 
Web www.quotesdb.info
Undernet  |  EFnet  |  Quakenet  |  Freenode  |  Dalnet  |  Ircnet  |  Galaxynet
Page: 1 2 3 4



Comments:

<0> what function returns the higher or lower byte of a word? the hi() and lo() functions don't exist in c++?
<1> MrMuscolo for what do you want them?
<1> "word" doesn't exist in C++ either
<0> short
<0> it is typedefd WORD = short
<1> there is no requirement in C++ for short to be 2 bytes
<1> or 2 octets to be more precise
<0> hmm really?
<1> really
<0> :D
<1> so...what are you trying to do?
<0> i have a file
<0> in which i have some 2-byte numbers in binary format
<2> MrMuscolo : ***uming that a short is two bytes, you can get the low by (Val&0xFF), and the high by (Val >> 8)
<0> and i have to convert it to a file containing 1-byte values....
<0> so what i did, was read them into a buffer, then divide them by 256, and write them out



<0> (copy them to a byte buffer)
<2> but this code isn't portable - it won't work correctly on a platform where a word isn't two bytes.
<0> but it doesn't work...
<1> MrMuscolo that seems a bit peculiar
<0> the problem is, that when i read the 2-byte values, i have endian-value incompatibility....
<1> lucky you
<0> in the file values i have high-endian numbers, and windows reads low-endian values i think... no?
<2> why don't you just read it by bytes ?
<0> i just thought about that...
<0> but i thought there was a more elegant way...
<0> then reading byte by byte, and the writing out only every secondf
<3> endianess is about processor type (how a particular processor interprets a word)
<2> you could have #defines depening on the endian of the specific processor, but I don't think there is anything elegant about it
<1> there's nothing elegant about handling endian problems
<0> yep... :|
<3> was the file written with the same architecture as the one you are reading it on?
<2> well, you could use htons/ntohsif you know that the file is in network byte ordering
<2> *if* you know
<0> i've downloaded the files
<0> GTOP database, if you know about it
<0> exception, can u tell me more about the htons/ntohsif?
<0> ah, got them... just two functions :))
<2> MrMuscolo : htons/ntohs, without if. two functions for translation from network ordering into your host's specific order and the other way around
<2> for systems with the same ordering as network they do nothing, for others they convert the byte ordering
<0> so if i have higher importance bytes first.... i use?....
<0> ntohs?
<2> the idea is that you always use ntohs for information that came from the network, and call htons for information that you're about to send to the network
<2> if there is no conversion required, both will just do nothing
<2> "network" here doesn't have to actually mean network, but any way of sharing information with computers that might use a different endian
<0> yes, i understand
<0> but i'm asking which endianness is when higher importance bytes are stored first?
<0> network endiannes, or not?
<1> hi-order 1st in network
<2> I never remember that, just google for endian
<0> thanks
<4> is it possible to have a cl*** 'wrap' the interface of another cl***, executing some code before each call, without knowing the interface in advance? (either directly or with some template or preprocessor 'tricks')
<5> Sounds like a bit too much
<5> Debuggers are quite good at that though
<4> exposing the interface is simple of course, with templates... template <cl*** T> Wrapper : public T { .. }, so adding something is not a problem, but having the code executed is :) I'm afraid it's not possible with templates alone, but I have no idea how I'd do this with the preprocessor
<4> or maybe something with implicit conversions that execute something
<4> I'm just here to gather some ideas... I realize that it will probably be a little 'hacky' though ;)
<1> luite what's the actual problem?
<4> I want to make a simple wrapper that does reference counting of an internal data object and copies that object when a non-const method is called on it
<1> so you want to write a generalized COW wrapper
<4> and I don't really have any specific requirements about the internal cl***es, other than that they have to be as small as possible, because I have quite a lot of them and don't want too much code duplication
<1> I don't think you have a prayer
<4> yup
<1> well, you can always pray, but I'd expect you get NO for an answer
<4> instead of praying I could also revert to an external macro preprocessor, but that's not as elegant as I'd like :)
<1> well, what's the actual _problem_ ... i.e. what's caused you to think that COW is the answer?
<4> I think it's the easiest from a user's point of view, when dealing with objects that are p***ed around quite often and where the internal data is quite large
<5> const &, &
<5> There, you're done
<5> If your users don't get that, fire them
<1> lo, Ashe` ... I like your answer
<4> just using references is not enough, because then, the objects would be destroyed by a single 'owning' object, there may be more than one that use a single data representation. requiring it to be duplicated would be inefficient, only when a certain object wants to modify the data (that can happen anywhere in the user's program), the data needs to be copied
<1> that doesn't make sense
<1> capriciously creating instances seems like folly, not a solution to anything
<4> let's say that there are two objects that use the same data object, a bitmap for instance, loaded from disc. I don't want the user to be responsible for destroying the bitmap, and as long as the bitmap is not modifified, the two should share the same bitmap for efficiency, if one of them wants to change it, it shouldn't be able to do anything with the bitmap the other cl*** uses
<1> you're suggesting that the person who's going to modify it isn't smart enough to make a copy themselves?



<4> so copy on write seems to be the logical solution, the bitmap can be freed when both objects that use it are destroyed (refcounting), and by using copy-on-write it wouldn't be able to alter the other ones bitmap
<4> it's not about being smart enough, but the objects are used throughout the application and changing is often done through events. I think that using copy on write is more elegant (and less error prone) than having to check whether other objects are using the same data and copying it manually every time it can be modified somewhere in the application
<1> well, have at it
<1> COW has some interesting drawbacks in a multi-threaded world
<1> many articles have been written on 8it
<1> err, on it
<1> and most implementations of std::string are no longer COW
<1> because of the problems
<4> seriously? hm, I'll read about it than
<4> then
<6> You need to check whether other objects are using it anyway, because if no other object is using it, then you don't need to make a copy.
<1> ah, right
<1> forgot about that one
<4> Run: that can be done automatically in the objects using the reference counting
<6> On the other hand...
<6> Object common_data;
<6> Object obj1(common_data); // only user
<6> obj1.change_data(); // doesn't make copy cause it only user...
<6> Object obj2(common_data);
<6> then results in something different then when you exchange the last two lines.
<4> yes I know, but if the common_data is really wrapped inside another cl***, you wouldn't have that problem. for the user it would just appear to be a single object that you can change. if you change it and then make a copy of it, using the copy constructor or the ***ignment operator, it's logical that the changed object is copied
<7> vector owns sort() but why do i still have to declare sort, like using std::sort;
<7> why?
<8> i don't know what 'owns' means... don't make stuff up
<9> it's std::sort()
<7> rdragon: is this correct?
<7> sort(student.homework.begin(), student.homework.end(), compare);
<7> OR
<7> sort(student.begin(), student.end(), compare);
<7> the 1st sort, won't work
<10> ?
<10> it's somewhat helpful to say what the variables in your examples are
<11> immigrants do not work either, you have to make them understand what "does not work" means in this country
<12> javaq_: Ask yourself, what do you want to sort? The students or the homeworks?
<7> homeworks
<7> i create a struct
<7> inside of struct is a vector of double named homework
<13> heh!
<7> Student_info student;
<12> You want to sorts the homeworks from the highest note the the worst?
<7> yes
<10> the first is fine then
<11> would you just define what "doesn't work" means already?
<12> sort(student.homework.begin(), student.homework.end() );
<12> No need for a compare function
<12> for doubles
<10> that would sort in ascending order
<7> k thanks i'll try
<12> YUY0x7: Oops, you are right
<10> use std::greater<double>() as the compare function
<10> and answer EwIck's question
<7> EwIck: everytime i compile stl_algo.h comes up and pointing to line 2508
<7> lin3 2508 of stl_algo.h is std::partial_sort(__first, __last, __last, __comp);
<10> what compiler?
<7> dev-c++ (best compiler)
<10> (says who?)
<12> Who is the moron who said that?
<7> the error just pops up
<10> and dev-c++ is not a compiler ;)
<7> k
<14> wizzord, beeeotches
<15> werd
<16> is this legal or not?
<16> int numbers[] = { 1, 2, 3, 4, 5, 6, 7 };
<10> yes
<16> YUY0x7: ok, coz some are like this
<16> int numbers[7] = { 1, 2, 3, 4, 5, 6, 7 };
<16> 7 inside bracket
<10> that's valid too
<16> YUY0x7: thanks
<10> np
<17> asl pls
<9> wrong place
<18> haha


Name:

Comments:

Please enter the result of the sum 63 + 46 (to avoid spam):






Return to #c++
or
Go to some related logs:

#MissKitten
abyys
#AllNiteCafe
#windows
What Scandinavian city is called The White City of The North ?
jazzyturk
what river are the cities of patna and calcutta on
#windows
proxy settings in linux
zwamle



Home  |  disclaimer  |  contact  |  submit quotes