Immer mehr private bytes :(
-
Das mit dem init war nur, falls du hinterher irgendwann die Elemente wieder auf den Anfangswert zurücksetzen willst, ansonsten ist es nicht nötig.
-
Sinds inzwischen schon weniger private bytes?
-
@Konstruktör: Beim Zurücksetzen mit std::fill macht das nicht viel Sinn. Aber man könnte natürlich statt std::fill auch deine init-Methode (obwohl ich den Namen immer noch nicht mag) in Verbindung mit std::for_each verwenden. Wie auch immer, ich denke das wird für den Fragen wohl zuviel sein. Mit der einfachen std::fill-Variante dürfte er wesentlich besser aufgehoben sein.
-
Ich weiß noch immer nicht, wie ich std::fill richtig einsetze.
Nicht mit einer Literalkonstanten, also so?std::string a; std::fill(oldJoinedPlayer.begin(), oldJoinedPlayer.end(), a); std::fill(joinedPlayer.begin(), joinedPlayer.end(), a);1>------ Build started: Project: SlowBob, Configuration: Release Win32 ------ 1>Compiling... 1>SlowBob.cpp 1>C:\Programme\Microsoft Visual Studio 8\VC\include\xutility(2726) : error C2679: binary '=' : no operator found which takes a right-hand operand of type 'const std::string' (or there is no acceptable conversion) 1> e:\c++\gold\slowbob\slowbob\SlowBob.h(57): could be 'SlowBob::oldJoinedPlayer &SlowBob::oldJoinedPlayer::operator =(const SlowBob::oldJoinedPlayer &)' 1> while trying to match the argument list '(SlowBob::oldJoinedPlayer, const std::string)' 1> C:\Programme\Microsoft Visual Studio 8\VC\include\xutility(2754) : see reference to function template instantiation 'void std::_Fill<std::_Vector_iterator<_Ty,_Alloc>,std::basic_string<_Elem,_Traits,_Ax>>(_FwdIt,_FwdIt,const std::basic_string<_Elem,_Traits,_Ax> &)' being compiled 1> with 1> [ 1> _Ty=SlowBob::oldJoinedPlayer, 1> _Alloc=std::allocator<SlowBob::oldJoinedPlayer>, 1> _Elem=char, 1> _Traits=std::char_traits<char>, 1> _Ax=std::allocator<char>, 1> _FwdIt=std::_Vector_iterator<SlowBob::oldJoinedPlayer,std::allocator<SlowBob::oldJoinedPlayer>> 1> ] 1> .\SlowBob.cpp(62) : see reference to function template instantiation 'void std::fill<std::_Vector_iterator<_Ty,_Alloc>,std::string>(_FwdIt,_FwdIt,const std::basic_string<_Elem,_Traits,_Ax> &)' being compiled 1> with 1> [ 1> _Ty=SlowBob::oldJoinedPlayer, 1> _Alloc=std::allocator<SlowBob::oldJoinedPlayer>, 1> _FwdIt=std::_Vector_iterator<SlowBob::oldJoinedPlayer,std::allocator<SlowBob::oldJoinedPlayer>>, 1> _Elem=char, 1> _Traits=std::char_traits<char>, 1> _Ax=std::allocator<char> 1> ] 1>C:\Programme\Microsoft Visual Studio 8\VC\include\xutility(2726) : error C2679: binary '=' : no operator found which takes a right-hand operand of type 'const std::string' (or there is no acceptable conversion) 1> e:\c++\gold\slowbob\slowbob\SlowBob.h(69): could be 'SlowBob::joinedPlayer &SlowBob::joinedPlayer::operator =(const SlowBob::joinedPlayer &)' 1> while trying to match the argument list '(SlowBob::joinedPlayer, const std::string)' 1> C:\Programme\Microsoft Visual Studio 8\VC\include\xutility(2754) : see reference to function template instantiation 'void std::_Fill<std::_Vector_iterator<_Ty,_Alloc>,std::basic_string<_Elem,_Traits,_Ax>>(_FwdIt,_FwdIt,const std::basic_string<_Elem,_Traits,_Ax> &)' being compiled 1> with 1> [ 1> _Ty=SlowBob::joinedPlayer, 1> _Alloc=std::allocator<SlowBob::joinedPlayer>, 1> _Elem=char, 1> _Traits=std::char_traits<char>, 1> _Ax=std::allocator<char>, 1> _FwdIt=std::_Vector_iterator<SlowBob::joinedPlayer,std::allocator<SlowBob::joinedPlayer>> 1> ] 1> .\SlowBob.cpp(63) : see reference to function template instantiation 'void std::fill<std::_Vector_iterator<_Ty,_Alloc>,std::string>(_FwdIt,_FwdIt,const std::basic_string<_Elem,_Traits,_Ax> &)' being compiled 1> with 1> [ 1> _Ty=SlowBob::joinedPlayer, 1> _Alloc=std::allocator<SlowBob::joinedPlayer>, 1> _FwdIt=std::_Vector_iterator<SlowBob::joinedPlayer,std::allocator<SlowBob::joinedPlayer>>, 1> _Elem=char, 1> _Traits=std::char_traits<char>, 1> _Ax=std::allocator<char> 1> ] 1>Build log was saved at "file://e:\C++\Gold\SlowBob\SlowBob\Release\BuildLog.htm" 1>SlowBob - 2 error(s), 0 warning(s) ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
-
struct oldJoinedPlayer { std::string ip; std::string id; }; std::vector<oldJoinedPlayer> oldJoinedPlayer; struct joinedPlayer { std::string ip; std::string id; }; std::vector<joinedPlayer> joinedPlayer;Liegts vielleicht an der Namensgebung?
-
Du hast in deinem std::vector keine Strings drin stehen. Da stehen struct's drin. Also mußt du std::fill auch eine struct übergeben.
-
Hab ich mir auch schon gedacht. Nur funktioniert's nicht:
struct emptyPlayer { std::string ip; std::string id; }; emptyPlayer emptyPlayer; std::fill(oldJoinedPlayer.begin(), oldJoinedPlayer.end(), emptyPlayer); std::fill(joinedPlayer.begin(), joinedPlayer.end(), emptyPlayer);1>------ Build started: Project: SlowBob, Configuration: Release Win32 ------ 1>Compiling... 1>SlowBob.cpp 1>C:\Programme\Microsoft Visual Studio 8\VC\include\xutility(2726) : error C2679: binary '=' : no operator found which takes a right-hand operand of type 'const SlowBob::{ctor}::emptyPlayer' (or there is no acceptable conversion) 1> e:\c++\gold\slowbob\slowbob\SlowBob.h(51): could be 'SlowBob::oldJoinedPlayer &SlowBob::oldJoinedPlayer::operator =(const SlowBob::oldJoinedPlayer &)' 1> while trying to match the argument list '(SlowBob::oldJoinedPlayer, const SlowBob::{ctor}::emptyPlayer)' 1> C:\Programme\Microsoft Visual Studio 8\VC\include\xutility(2754) : see reference to function template instantiation 'void std::_Fill<std::_Vector_iterator<_Ty,_Alloc>,SlowBob::{ctor}::emptyPlayer>(_FwdIt,_FwdIt,const SlowBob::{ctor}::emptyPlayer &)' being compiled 1> with 1> [ 1> _Ty=SlowBob::oldJoinedPlayer, 1> _Alloc=std::allocator<SlowBob::oldJoinedPlayer>, 1> _FwdIt=std::_Vector_iterator<SlowBob::oldJoinedPlayer,std::allocator<SlowBob::oldJoinedPlayer>> 1> ] 1> .\SlowBob.cpp(66) : see reference to function template instantiation 'void std::fill<std::_Vector_iterator<_Ty,_Alloc>,SlowBob::{ctor}::emptyPlayer>(_FwdIt,_FwdIt,const SlowBob::{ctor}::emptyPlayer &)' being compiled 1> with 1> [ 1> _Ty=SlowBob::oldJoinedPlayer, 1> _Alloc=std::allocator<SlowBob::oldJoinedPlayer>, 1> _FwdIt=std::_Vector_iterator<SlowBob::oldJoinedPlayer,std::allocator<SlowBob::oldJoinedPlayer>> 1> ] 1>C:\Programme\Microsoft Visual Studio 8\VC\include\xutility(2726) : error C2679: binary '=' : no operator found which takes a right-hand operand of type 'const SlowBob::{ctor}::emptyPlayer' (or there is no acceptable conversion) 1> e:\c++\gold\slowbob\slowbob\SlowBob.h(57): could be 'SlowBob::joinedPlayer &SlowBob::joinedPlayer::operator =(const SlowBob::joinedPlayer &)' 1> while trying to match the argument list '(SlowBob::joinedPlayer, const SlowBob::{ctor}::emptyPlayer)' 1> C:\Programme\Microsoft Visual Studio 8\VC\include\xutility(2754) : see reference to function template instantiation 'void std::_Fill<std::_Vector_iterator<_Ty,_Alloc>,SlowBob::{ctor}::emptyPlayer>(_FwdIt,_FwdIt,const SlowBob::{ctor}::emptyPlayer &)' being compiled 1> with 1> [ 1> _Ty=SlowBob::joinedPlayer, 1> _Alloc=std::allocator<SlowBob::joinedPlayer>, 1> _FwdIt=std::_Vector_iterator<SlowBob::joinedPlayer,std::allocator<SlowBob::joinedPlayer>> 1> ] 1> .\SlowBob.cpp(67) : see reference to function template instantiation 'void std::fill<std::_Vector_iterator<_Ty,_Alloc>,SlowBob::{ctor}::emptyPlayer>(_FwdIt,_FwdIt,const SlowBob::{ctor}::emptyPlayer &)' being compiled 1> with 1> [ 1> _Ty=SlowBob::joinedPlayer, 1> _Alloc=std::allocator<SlowBob::joinedPlayer>, 1> _FwdIt=std::_Vector_iterator<SlowBob::joinedPlayer,std::allocator<SlowBob::joinedPlayer>> 1> ] 1>Build log was saved at "file://e:\C++\Gold\SlowBob\SlowBob\Release\BuildLog.htm" 1>SlowBob - 2 error(s), 0 warning(s) ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
-
emptyPlayer emptyPlayer?
Du kannst ein Objekt nicht genauso nennen wie eine Klasse. Und im übrigen solltest du zum Löschen auch keine eigene struct anlegen.
-
Hey!
"Und im übrigen solltest du zum Löschen auch keine eigene struct anlegen."
Warum nicht? Wie sonst?
MfG
-
Hab mich nicht ganz genau ausgedrückt. Ich meinte damit, du sollst keine neue Klasse (struct) schreiben. Ein eigenes Objekt, das du übergeben kannst, brauchst du natürlich schon. Aber das muß vom selben Typ sein wie die Objekte, die im vector liegen.
-
Bin anscheinend total außer Übung. Also einfach noch ein Objekt anlegen... klar.. mal sehn wie weit ich komme :|
-
Hey!
Ist es möglich, diesem vector
struct sJoinedPlayer { std::string ip; std::string id; }; std::vector<sJoinedPlayer> joinedPlayer;ip und id separat zu speichern? Ich müsste ja eine Struktur pushen...
MfG
-
Hallo
der Vector hat als Elementtyp die Struktur, also must auch immer als Wert eine Instanz der Struktur hinzufügen. Etwas anderes geht nicht.
bis bald
akari
-
Hihi, hab doch eh schon alles geschrieben, musst bloss lesen und machen. So halt, is ja net so schwer zu checken:
void Foo::Moo() { joinedPlayer temp; // hier: joinedPlayer=Typname std::fill(&joinedPlayer[0], &joinedPlayer[sizeof(this->joinedPlayer)/sizeof(this->joinedPlayer[0])], temp); // hier: joinedPlayer=Name des Members // ferdich }Oder eben wie gesagt nen std::vector<joinedPlayer> verwenden was das einfachste und beste wäre. Blubb

Und du solltest deine Member nicht gleich wie deine Typen nennen. Das verwirrt.
Du kannst ein Objekt nicht genauso nennen wie eine Klasse
Wohl, das geht (leider *würg*).
Sowas...struct T{ int i; }; void Sepp() { T T; T.i = 0; }...compiliert und läuft ohne Fehler. Wird halt lästig bei sizeof wenn "T" ein "T[100]" ist. Was ist dann "sizeof(T)"?

-
Hey!
Also, jetzt habe ich alles belassen, jedoch statt memset nun für jedes Objekt Clear() aufgerufen. (ip = "";, id = "";)
Es wird trotzdem immer mehr Speicher verbraucht ...
-
Das Problem ist ja, es waren nun in einer Stunde maximal 10 Spieler im Server, daher sind auch nur maximal 10 ID's und IP's gespeichert worden. Ich habe doch nur 3 Arrays, wie kann das so viel Speicher nehmen??
-
Du hast nirgens gezeigt was mit dem Objekt passiert. Das ganze rumdocktorn an der der gezeigten Klasse sind IMHO sinnlos. Ich sehe die warscheinlichkeit des Speicherverbrauches im Umfeld für viel größer.
Lediglich eine kurze Main wurde aufgezeigt, die eine Instanz der Klasse zeigt. Aber nicht , wie z.b. die IP und Spielernamen in das Objekt kommen.
Auch habe ich vermutlich überlesen, wie denn festgestellt wird, das der Prozess zunehmend speicher benötigt.
-
Hey!
Hatte die alte Datei gestartet...Nun scheint es konstant bei 628K zu bleiben

-
Dieser thread ist total scheisse. 70 Seiten und ich hätte nur memset nicht verwenden dürfen...
Wollt ihr den nicht löschen

-
Ach, eins interessiert mich noch. Warum wurde so viel Speicher gefressen? Weil undefinierte Speicherstellen mit 0 vollgeschrieben wurden? Oder leert memset mit 0 komplett?
MfG