« first day (268 days earlier)      last day (4672 days later) » 

12:00 AM
Nothing more interesting in the other cpp files of those below AbstractNode.
Hmm, I should be looking at the actual string append code perhaps?
AbstractNode returns EMPTY_STRING.
AbstractContainerNode doesn't override.
So, in Element:
XMLString Element::innerText() const
{
	XMLString result;
	Node* pChild = firstChild();
	while (pChild)
	{
		result.append(pChild->innerText());
		pChild = pChild->nextSibling();
	}
	return result;
}
I don't really see how append could be leaking memory here... :-/
XMLString is just a std::string.
 
I really doubt the leak comes from inside std::string. This would be a very serious bug.
 
Any idea where I can find the source files of STL on my Gentoo?
 
Do you have an IDE or something?
 
Not on Windows.
 
(And did you change your code to not have deletes and rely on RAII and smart pointers instead? I would do that first, instead of going on a wild goose chase through the ugly STL code)
Typing g++ -v should yield a list of all the include directories.
 
12:08 AM
template<typename _CharT, typename _Traits, typename _Alloc>
    basic_string<_CharT, _Traits, _Alloc>&
    basic_string<_CharT, _Traits, _Alloc>::
    append(const basic_string& __str)
    {
      const size_type __size = __str.size();
      if (__size)
	{
	  const size_type __len = __size + this->size();
	  if (__len > this->capacity() || _M_rep()->_M_is_shared())
	    this->reserve(__len);
	  _M_copy(_M_data() + this->size(), __str._M_data(), __size);
	  _M_rep()->_M_set_length_and_sharable(__len);
 
Ugh, ugly.
 
Yeah. :D
 
@mru Interesting. Didn't knew that exit was so bad.
 
mru
@MartinhoFernandes me neither ;0
 
12:10 AM
Well, I mean, it's not that bad, it just confuses valgrind.
 
mru
@TomWij valgrind.org/docs/manual/faq.html#faq.reports (section 4.1, i think so removes the anchor)
ah no
 
Because when you call exit, you really want it to go out and not wade around calling destructors.
 
@mru: Hmm, I do use exit(0), should try to see if I can get it to go back down to the main and properly exit there.
 
mru
@MartinhoFernandes depends, you may want to clean some resources, drop some connections etc
 
If it's abnormal termination, you usually don't want to do any of that.
 
mru
12:11 AM
but i won't check the standard for now
 
exit(0) is something you can almost always replace with proper returns from main.
 
@mru: So, the fix is to use -DGLIBCXX_FORCE_NEW as a compile flag?
Q: Oh hi! I have a problem with my code. A: Fix your compiler.
 
Yeah, try that.
 
mru
@TomWij i don't know what the fix is, i just pointed you to the possibility that everything is fine and it is a false positive
 
I'll be digging through the standard to see if this is conformant behavior.
 
12:14 AM
@mru: We want the memory to release as soon as possible, if possible.
I'll reboot and try that.
 
mru
oh long time ago i wrote c++...
 
brb
 
mru
reboot?!
 
I think he's dual booting into Linux.
 
mru
ah thought he had to restart his system…maybe some embedded stuff
 
12:15 AM
okay
 
Already? You reboot from Windows in 2 minutes?
 
SSD
Minimal Gentoo with Xfce
Just for ensuring that C++ I write works under Linux.
 
Yes, but Windows...
 
Restarting to Windows is just as fast as this reboot.
 
mru
btw. you may want to use llvm and clang, it provides a nice static analyzer
 
12:17 AM
Boiled down the boot with Windows Performance Toolkit, for example, Search Indexer takes 5 seconds of my boot so I disabled that and use Search Everything instead (kinda comparable to locate).
hmm
the -D, does that need to happen on compiling or on the linking?
Quite some time ago that I put a -D in a Makefile. :(
 
Compilation.
 
mru
compiling
 
It's like a global #define.
 
mru
it is like define
@MartinhoFernandes hehe ;0
 
Ah, makes sense.
make clean; make...
30 more seconds...
 
12:22 AM
Just checked. The Final Draft of the upcoming C++ standard states that exit destroys objects with thread storage duration associated with the current thread, and objects with static storage duration. It explicitly mentions that automatic objects are not destroyed as a result of calling exit().
 
I don't see the memory decreasing so dunno if it's working...
 
So this behavior seems conforming.
@TomWij What does valgrind report?
 
==2998== 12,880,736 bytes in 37 blocks are definitely lost in loss record 93 of 93
==2998==    at 0x4C2747E: operator new(unsigned long) (vg_replace_malloc.c:261)
==2998==    by 0x5A3AC88: std::string::_Rep::_S_create(unsigned long, unsigned long, std::allocator<char> const&) (in /usr/lib64/gcc/x86_64-pc-linux-gnu/4.4.4/libstdc++.so.6.0.13)
==2998==    by 0x5A3BC4A: std::string::_Rep::_M_clone(std::allocator<char> const&, unsigned long) (in /usr/lib64/gcc/x86_64-pc-linux-gnu/4.4.4/libstdc++.so.6.0.13)
Same.
 
You compiled with the -D thing?
And using return 0 instead of exit(0)?
 
# object files
bin/%.o: src/%.cpp external/include/Poco | outputdirs
	@echo 'Building $(<:src/%=%)'
	@g++ -g -Wall -c $(INCLUDE) -DGLIBCXX_FORCE_NEW -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o"$@" "$<"

# executables
bin/%.exe: external/lib bin/%.o $(ALLOBJECTS)
	@echo 'Linking $@'
	@g++ -o "$@" "$(@:%.exe=%.o)" $(ALLOBJECTS) $(LIBPATH) $(LIBS)
 
12:24 AM
Or is that too complicated to change (shoudn't be :)?
 
Didn't make a change...
Should I try to get the exit(0) right?
 
mru
yes, and if this doesn't work, just try clang++ instead, maybe it helpes (should use a different stl)
 
As a quick fix, you can try throwing instead of exit(0).
:)
That is required to do proper cleanup.
 
@MartinhoFernandes: Is there a simple Exception that doesn't need an include?
 
12:26 AM
But do that only as temporary change for testing this!
You can throw anything. throw 42; should work.
Don't ever write that in real code, ok?
 
:P
 
mru
oh i must admit i don't have good knowledge of c++0x…just know the rvalue references...
 
It's busy now.
@MartinhoFernandes: Hmm, but still, should I be worried about the application taking up memory after the file has been sent and saving?
 
What are you using to take this conclusion?
 
Whenever I send a file of 9 MB I see the memory of the process to be 9 MB higher after the file has been sent and saved.
 
12:30 AM
You see that in top or similar?
 
==3215== 12,176,288 bytes in 35 blocks are definitely lost in loss record 373 of 373
==3215==    at 0x4C2747E: operator new(unsigned long) (vg_replace_malloc.c:261)
==3215==    by 0x5A3AC88: std::string::_Rep::_S_create(unsigned long, unsigned long, std::allocator<char> const&) (in /usr/lib64/gcc/x86_64-pc-linux-gnu/4.4.4/libstdc++.so.6.0.13)
==3215==    by 0x5A3BC4A: std::string::_Rep::_M_clone(std::allocator<char> const&, unsigned long) (in /usr/lib64/gcc/x86_64-pc-linux-gnu/4.4.4/libstdc++.so.6.0.13)
That's after the throw.
terminate called after throwing an instance of 'int'.
 
Hmm wait, maybe you should wrap main around a try { } catch(...) {} to avoid calling terminate. I'm not sure if it's required to cleanup if it results in termination.
 
Still the same problem.
 
Confirmed, it isn't required to do so.
Ok, it's not a false positive.
 
Can you check this Pastebin to see if it makes any sense?
Because those errors are provided too and they seem quite relevant to the deconstructors of the XML stuff...
 
12:38 AM
Looking in the GCC bugzilla, I can't find a bug registered for this. Since GCC 4.4 is rather old, I doubt a memory leak in string.append would go unnoticed. That leaves your code and Poco.
Ow, invalid writes.
 
If I interpret the Pastebin correctly, I shouldn't be using AutoPtr because I'm disallowing them from properly deconstructing?
 
Dammit, Poco's docs are rather short on this.
 
I've gave you the deconstructors a bit back.
 
Oh, yes.
(It's destructors btw)
 

Deconstructor stuff.

44 mins ago, 3 minutes total – 13 messages, 2 users, 0 stars

Bookmarked 7 secs ago by TomWij

 
12:41 AM
> If an AutoPtr is assigned an ordinary pointer to an object (via the constructor or the assignment operator), it takes ownership of the object and the object's reference count remains unchanged. If the AutoPtr is assigned another AutoPtr, the object's reference count is incremented by one by calling duplicate() on its object.
 
Oh, I usually type that wrong.
 
Got it.
Yes, that AutoPtr on the root element is probably bad.
Taking an AutoPtr from a naked pointer does not increment the reference count for some reason.
 
It uses more a bit more memory now, huh...
Let's wait for what valgrind has to say...
Oh, right, the AutoPtr stuff is used in two procedures, adjusting the second one and testing again...
Okay, the errors are gone.
 
It worked?
 
But, this is the restulting valgrind trace:
Quite different, still a memory leak.
 
12:49 AM
Yeah :(
It's almost 2 AM here. I've gotta go to sleep real soon. Tomorrow I'm starting on a new project at work, and I want to be sharp :)
 
Looking at it
==3554== 25,063,537 bytes in 297 blocks are indirectly lost in loss record 108 of 108
==3554==    at 0x4C2747E: operator new(unsigned long) (vg_replace_malloc.c:261)
==3554==    by 0x5A3AC88: std::string::_Rep::_S_create(unsigned long, unsigned long, std::allocator<char> const&) (in /usr/lib64/gcc/x86_64-pc-linux-gnu/4.4.4/libstdc++.so.6.0.13)
==3554==    by 0x5A3B6C4: ??? (in /usr/lib64/gcc/x86_64-pc-linux-gnu/4.4.4/libstdc++.so.6.0.13)
==3554==    by 0x5A3B90A: std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, unsigned long, std::allocator<c
This is the problem if I am right?
A bug inside Poco I think.
Dunno from where that code is called, can I somehow get more stack information on that?
 
No idea.
 
I believe it's in the ParseString, @Martinho.
	Command * NodeProtocol::deserialize(const string & msg)
	{
		//create a parser
		DOMParser xmlParser;

		//Get the root node.
		AutoPtr<Document> doc = xmlParser.parseString(msg);
yup
I'm now going inside Poco to see.
 
Hmm, seems so.
Good luck :) I'm leaving now.
Bye.
 
Thanks already, @MartinhoFernandes. :)
@MartinhoFernandes: Apparently, they are returning an auto-pointer in the parseString, I'll check the destructors to see if clean up has been done there.
 
1:25 AM
Can someone tell me where i can get help for vb.net?
 
 
2 hours later…
3:21 AM
@MartinhoFernandes: Question got answered, apparently I should have traced where the data gets stored and what happens to that. Because the problem was missing virtual destructors...
Well, learned a lot by it. How to look into frameworks, preferring value > reference > pointer unless I really need them, to check valgrind both ways, to make sure that when I use a base class that it has a virtual destructor when it has field members, and so on.
This seemed to resolve another issue too, so quite funny the problem is now resolved for both the node and client.
They both are around 512 KB when launched, node seems to go 10 MB (idle) - 20 MB (sending) when sending a 10 MB file, but that's probably because of the pool implementation of the string.
There are some 1K and lower memory leaks left, but they don't sum up to much overhead anymore...
The room topic kind of matches the problem I had, you guys set that on purpose! :P
 
Yeah the value reference pointer thing is interesting. I see pointers now as "maybe" values, they carry extra info you usually don't need (null or not-null).
java encumbers every object with that extra info
er, it encumbers every object reference. It must limit optimization.
 
3:50 AM
@TomWij You want to use a virtual dtor when the object might be destroyed via a pointer/reference to the base class. If something is going to act as a base class, you usually want it to have a virtual dtor.
 
4:38 AM
This is amazing. And the comments in the question... priceless.
 
5:32 AM
@MartinhoFernandes Yes, but I didn't inhale. Honest!
 
 
2 hours later…
7:57 AM
> In the closing session of the 6th International Congress of Linguists, held in Paris in 1948, congress president Joseph Vendryes remarked that modern linguistics was in a crisis, and that linguists were not even in agreement on what a word is, one of the fundamental concepts of their object of studies (cf. Togeby 1949: 97)
The more you study something, the less clear it becomes. This feels familiar, somehow..
 
Can I ask a simple NooB question here ? Why C++ class doesn't allow to initialize an array with default values >?
 
@MichaelIV In a sense, there never was syntax for it.
i.e. you can do T array[n] = { ... } but not T array[n](...)
and member initialization syntax uses the second form only
This is fixed with C++0x though (plus, there's std::array). In the meantime, I suggest boost::array.
 
So you guys suggest using stl array classes instead ?
 
There is no standard array class for C++03.
(there is std::vector)
 
8:42 AM
Morning
 
@MichaelIV I suggest updating your compiler. g++ has supported uniform initialization for quite some time now.
 
I work with VS 2010 .Doesn't it have the updated compiler?
 
Good Morning
 
@MichaelIV: Updated but not up to date.
 
@wilx
@wilx . He He
Do you mean gcc compiler?
 
8:56 AM
No, I meant VS 2010. It has some C++11 features but not all and in case of rvalue references slightly out of date.
 
Can I ask you for a reference how to update it ?
 
I do not think there is any new VS than 2010.
You will have to wait a bit for MS to catch up.
 
9:14 AM
@MichaelIV gcc is a C compiler which certainly does not have uniform initialization :)
And why do you use array members, anyway?
 
Xeo
9:52 AM
room topic changed to Lounge<C++>: NOT the JavaScript help desk.
 
10:08 AM
I have this JS question.
 
I was wondering if people in here do C as well? To the best of my abilities, I can't find a C room.
 
I know a bit of C too, obviously, but I find it extremelly hard to achieve anything with it. It dealing with raw memory allocation/initialization gets tedious. Basically, it lacks any sort of reasonable standard containers/strings library too much for me.
 
Xeo
@wilx It's not like you can't have smartpointer in C
It's just a tad more tedious. :D
 
@Xeo How can you have one without RAII?
 
@RomanLuštrik I've done C
 
Xeo
10:19 AM
@MartinhoFernandes Welll... right, but you can have refcounted pointer at least
 
Meh, pretty weak. The "smartest" thing about smart pointers is the automatic management.
 
@Xeo: The problem I have is that if I want to do anything non-trivial, I have to build up my own standard library stuff like containers and strings first. Or I have to use some 3rd party library.
Frankly, I do not know about any general purpose containers library for C at all.
 
They should be called CanBeUsefulInSomeSituationPointer.
 
Xeo
@wilx Well, obvious, because you can't really have them
You can only make-do with void* with lack of templates
 
Xeo
10:25 AM
hahaha
 
A trick I've seen for linked-lists or tree-like structures involved write the code for a generic typedef struct node { struct node* next; } Node; and then casting all over. Apparently it works if your node struct starts with the pointer.
 
Xeo
#define VECTOR(T) \
  struct Vector##T{ \
  // ...
 
Not sure if it involves some UB or implementation defined behavior somewhere.
 
#define ever (;;)
my fav define.
All compilers should execute a reboot when you run code that has undefined behavior.
 
Xeo
reboot takes too long and can be canceled, just make it a soft-reset
 
10:33 AM
Just anything that will annoy the programmer.
 
@MartinhoFernandes I'm wondering if using offsetof macros makes it legitimate; I'm taking a cursory glance at klist but it seems to resort to implementation tricks.
 
Noise on the PC Speaker.
 
@ÓlafurWaage Boring. UB should lead to launching nethack.
Just like #pragma did in older versions of GCC.
 
hehehe
 
10:45 AM
@Xeo: Yeah, I used that with base void* based container and forwaring functions with a concrete type doing casts.
But it still sucks.
 
Of course it sucks. It's C.
 
Hey guys, can I ask a JavaScript question?
 
Okay, bye.
(I feel this has immense trolling potential.)
 
@CatPlusPlus Hello.
 
11:20 AM
Woo, we've got inline editing now.
 
Xeo
Huh?
 
Is the boost::unique_ptr in the interprocess library like std::unique_ptr?
@Xeo Try editing an SO post.
 
Xeo
Oooh, nice
 
@MartinhoFernandes If it relies on Boost.Move, yes.
 
11:39 AM
hey
 
Morning...
 
11:55 AM
Sorry, had to go away for a meeting. What I'm trying to do is run sample code at the end of this page. crasseux.com/books/ctutorial/…
I get a bunch of warnings, possibly related to implicit use of int and return. Can anyone replicate this?
 
Make those functions that return void.
Plus declare them before use (i.e. before main)
(those are my suggestions, you can also ignore the warnings altogether)
 
Also, add a return on main.
That is required in C.
Not in C++, though.
 
Not required for C99
 
Oh, you're right..
C99 is still a mystery to me.
 
12:02 PM
Well
Using // style comments? C99!
 
@LucDanton Warnings all gone!
Thanks a bunch.
 
 
1 hour later…
1:31 PM
This question needs a retag
0
Q: C/C++ parse command line

abcdeHow to effectively parse this command line in C++? program -parameter1=value1 -parameter2=value2 -parameter3=value3 How to effectively drop a combination of the parameter and value -parameter=value I am trying to use this code but it does not work properly: parameter[256], value[256], whil...

 
@kbok A retag to what? Seems fine.
Also, you already have the rep to do so yourself :)
 
The code in the question is using char* and friends, so I guess it's a C question, right ?
 
Oh that. Should've read the title.
The body mentions only C++, so I think it's fair to treat it as such (and suggest non-C-ish alternatives, of course).
I changed the title.
 
I left a comment asking for more precisions.
 
1:44 PM
If boost is not available (it should!), getopt_long is a reasonable choice that is available in POSIX systems, and it takes char*, so...
 
mru
2:01 PM
the google gflags lib is also quite nice iirc
 
sbi
2:29 PM
@kbok Added a c tag.
 
2:44 PM
damn
turns out that if you want types as expressions, the grammar is not easy to define
 
Another schmuck that thinks polymorphic multiplication is a good idea.
1
Q: C++ returning an object throw an interface

Mauro BruniI want to design a common interface which has a method that let me multiply two object which has this interface, returning a new object of the same class as the result. In order to keep it easy, I'm going to focus just on one class which implement this interface. The problem: My problem is the re...

@DeadMG You're finally leaving theoretical exploration and getting your hands dirty?
 
I think that attempting to define a grammar in my vague memories of EBNF still counts as theoretical
oh man
I so badly want the ability to block-select text vertically as well as horizontally like you can do in Visual Studio 2010
 
What editor are you using?
 
I'm using an editor?
was just typing it straight into my blog post :P
 
2:58 PM
now I'm using VS
makes my intended formatting much easier
not the first time I've used Visual Studio as a general-purpose text editor :P
 
Xeo
try notepad++
or pspad
 
I use Notepad2, and vim.
 
why do that when I have Visual Studio? :P
 
Xeo
Because VS starts up like a turtle - fuckin slow
 
stop crying and buy an SSD
:D
 
Xeo
2:59 PM
I got one
 
or just leave VS open all the time
 
Xeo
Well, I do have my "blargh" toy project open all time
 

« first day (268 days earlier)      last day (4672 days later) »