Wednesday, October 14, 2015

Digest for comp.lang.c++@googlegroups.com - 17 updates in 5 topics

Lynn McGuire <lmc@winsim.com>: Oct 14 12:38PM -0500

I would like to calculate the size of a very complex object at runtime. This object has 100 instance variables including several
vectors that contain vectors, etc. Is there an easy way to do this? Obviously sizeof is not going to work.
 
Thanks,
Lynn
Victor Bazarov <v.bazarov@comcast.invalid>: Oct 14 01:47PM -0400

On 10/14/2015 1:38 PM, Lynn McGuire wrote:
> This object has 100 instance variables including several vectors that
> contain vectors, etc. Is there an easy way to do this? Obviously
> sizeof is not going to work.
 
Since it's very implementation-specific, perhaps the easiest way is to
take a reading of the memory used by your process (using OS-specific
means), then allocate N of those objects, then take another reading
(using the same OS-specific means), then divide the difference between
the two readings by N. Choose different values of N and do more than
one test to get as close to the actual size as possible.
 
V
--
I do not respond to top-posted replies, please don't ask
Paavo Helde <myfirstname@osa.pri.ee>: Oct 14 02:08PM -0500

> runtime. This object has 100 instance variables including several
> vectors that contain vectors, etc. Is there an easy way to do this?
> Obviously sizeof is not going to work.
 
If the data structures grow and reduce during the program and you want to
know the total memory usage associated with a specific object at any random
moment, then pretty much the only way is to calculate it the hard way (by
e.g. adding a specific function to each of your classes which sums up the
dynamic memory usage of members of the class). With some template trickery
this can be automated to some extent for STL containers I believe.
 
If your 100 member variables do not manage dynamic memory then they are
included in sizeof() of the parent class and do not require extra care.
 
One question is for which purpose do you need this information? There may
be other simpler means for achieving the goal.
 
hth
Paavo
bartekltg <bartekltg@gmail.com>: Oct 14 10:02PM +0200

On 14.10.2015 21:08, Paavo Helde wrote:
> e.g. adding a specific function to each of your classes which sums up the
> dynamic memory usage of members of the class). With some template trickery
> this can be automated to some extent for STL containers I believe.
 
Is there any trick to do something with every member of a class?
 
A tupple contains all members would be enough;)
 
bartekltg
Paavo Helde <myfirstname@osa.pri.ee>: Oct 14 04:18PM -0500

bartekltg <bartekltg@gmail.com> wrote in
>> class). With some template trickery this can be automated to some
>> extent for STL containers I believe.
 
> Is there any trick to do something with every member of a class?
 
Not to my knowledge, C++ still lacks full introspection capabilities.
 
> A tupple contains all members would be enough;)
 
This would probably involve adding support for std::tuple in language
core (similar to std::initializer_list). Also, I foresee at least some
conceptual problems with private data members.
 
Cheers
Paavo
mark <mark@invalid.invalid>: Oct 14 11:21PM +0200

On 2015-10-14 19:38, Lynn McGuire wrote:
> This object has 100 instance variables including several vectors that
> contain vectors, etc. Is there an easy way to do this? Obviously
> sizeof is not going to work.
 
If you only want to do a few test measurements, you can replace
new/delete/malloc/free and keep track the allocated memory.
Lynn McGuire <lmc@winsim.com>: Oct 14 04:28PM -0500

On 10/14/2015 4:21 PM, mark wrote:
>> contain vectors, etc. Is there an easy way to do this? Obviously
>> sizeof is not going to work.
 
> If you only want to do a few test measurements, you can replace new/delete/malloc/free and keep track the allocated memory.
 
I have thousands of dissimilar objects in our software (600 classes, etc).
 
Currently, I have have one instance of the object in question. The object can be, depending on the size of the model, from 50 KB to
50 MB in size (swag). We are moving to multiple instances of the object in question so I would like to estimate file storage needed.
 
Thanks,
Lynn
Ian Collins <ian-news@hotmail.com>: Oct 15 10:38AM +1300

Lynn McGuire wrote:
> I would like to calculate the size of a very complex object at
> runtime. This object has 100 instance variables including several
> vectors that contain vectors, etc. Is there an easy way to do this?
 
Please wrap your lines!
 
> Obviously sizeof is not going to work.
 
It would be part of the solution. The easiest solution is to add a size
member function that sums sizeof(the class) and capacity of the
container members.
 
An alternative to using capacity would be to use a custom allocator for
the container members.
 
--
Ian Collins
Luca Risolia <luca.risolia@linux-projects.org>: Oct 14 11:41PM +0200

Il 14/10/2015 19:38, Lynn McGuire ha scritto:
> This object has 100 instance variables including several vectors that
> contain vectors, etc. Is there an easy way to do this? Obviously
> sizeof is not going to work.
 
use of sizeof + global operator new / operator new[] replacements are
probably a good starting point
Paavo Helde <myfirstname@osa.pri.ee>: Oct 14 05:10PM -0500


> Currently, I have have one instance of the object in question. The
> object can be, depending on the size of the model, from 50 KB to 50 MB
> in size (swag).
 
50 MB ought be visible pretty well already at the OS level. Just add some
code to make a deep copy of it (should be trivial if these are really
vectors of vectors) and observe the process size immediately before and
after.
 
> We are moving to multiple instances of the object in
> question so I would like to estimate file storage needed.
 
File storage? If your object is serializable to a file why don't you just
serialize it and look at the file size?
ram@zedat.fu-berlin.de (Stefan Ram): Oct 14 10:08PM

>I would like to calculate the size of a very complex object at runtime.
>Obviously sizeof is not going to work.
 
»5.3.3 Sizeof [expr.sizeof]
 
1 The sizeof operator yields the number of bytes in the
object representation of its operand.«
 
If »Obviously sizeof is not going to work«, then
»size of an object« might have a special meaning
to you.
woodbrian77@gmail.com: Oct 14 09:34AM -0700

On Tuesday, October 13, 2015 at 12:10:56 PM UTC-5, Scott Lurndal wrote:
 
> So your service generates relocatable object code, then? For
> which architecture? i686? ia64? x86_64? s390? armv7? armv8? mips?
> powerpc?
 
No.

> Or do you just generate C++ source that the end-user compiles?
 
Yes.
 
> and operating system designers to quantify system performance).
> Particularly given the propensity of operating systems to cache
> recently used files (read: header files) in memory.
 
I've been talking about the efficiency of the code generation
not the time to distribute the generated code. The CMW is
free if you use my server. If someone wants to, they can buy
a license and use the CMW locally.
 
We should go back to the original post though. Java and C#
swamp C++ when it comes to serialization. That may be
because those languages have more automated support for
serialization.
 
 
Brian
Ebenezer Enterprises - This is my story, this is my song.
Praising my Saviour (Yeshua aka Jesus) all the day long.
 
http://webEbenezer.net
Mark <i@dontgetlotsofspamanymore.net>: Oct 14 07:51AM +0100

I am trying to write some code to convert local time to UTC. I am
using the following which works in many circumstance but a client in
the US has found it not working correctly:
 
void convertToUTC(const char *input, char *output)
{
struct tm tm_;
 
memset(&tm_, 0, sizeof(struct tm));
 
if (!strptime(input, "%d-%b-%Y %T", &tm_))
{
// failed
return;
}
time_t thetime = mktime(&tm_);
// Convert to UTC
struct tm gmcal = *gmtime(&thetime);
thetime = mktime(&gmcal);
 
struct tm *tm_p;
struct tm tm2;
 
tm_p = gmtime_r(&thetime, &tm2);
 
sprintf(output, "%4d-%02d-%02dT%02d:%02d:%02dZ",
tm_p->tm_year + 1900,
tm_p->tm_mon + 1,
tm_p->tm_mday,
tm_p->tm_hour,
tm_p->tm_min,
tm_p->tm_sec);
}
 
"13-Oct-2015 06:57:17" --> "2015-10-13T22:57:17Z"
 
Output from 'date' command:
date; date -u
Tue Oct 13 06:58:10 PDT 2015
Tue Oct 13 13:58:10 UTC 2015
 
Can someone tell me how to fix this?
"Lőrinczy Zsigmond" <zsiga@nospam.for.me>: Oct 14 11:28AM +0200

I think it could be simplified
 
void convertToUTC(const char *input, char *output)
{
struct tm tmloc, tmutc;
time_t thetime;
 
memset(&tmloc, 0, sizeof tmloc);
memset(&tmutc, 0, sizeof tmutc);
 
if (!strptime(input, "%d-%b-%Y %T",&tmloc))
{
// failed
return;
}
thetime = mktime(&tmloc);
gmtime_r(&thetime, &tmutc);
 
sprintf(output, "%4d-%02d-%02dT%02d:%02d:%02dZ",
tmutc.tm_year + 1900,
tmutc.tm_mon + 1,
tmutc.tm_mday,
tmutc.tm_hour,
tmutc.tm_min,
tmutc.tm_sec);
}
Mark <i@dontgetlotsofspamanymore.net>: Oct 14 10:38AM +0100

On Wed, 14 Oct 2015 11:28:17 +0200, L?rinczy Zsigmond
> tmutc.tm_min,
> tmutc.tm_sec);
>}
 
Won't this behave in exactly the same way as my code?
Nobody <nobody@nowhere.invalid>: Oct 14 03:01PM +0100

On Wed, 14 Oct 2015 07:51:40 +0100, Mark wrote:
 
> return;
> }
> time_t thetime = mktime(&tm_);
 
You should probably set tm_.is_dst=-1 prior to calling mktime(). That will
cause it to attempt to determine whether or not DST is in effect based
upon the date and time. That still has a problem when clocks go back as
any time within the last hour of DST or the first hour afterwards will be
ambiguous.
 
If the is_dst is field zero, DST is not used.
 
But that's not the biggest issue here.
 
 
> struct tm *tm_p;
> struct tm tm2;
 
> tm_p = gmtime_r(&thetime, &tm2);
 
This is bogus. You're taking a time_t (number of seconds since the epoch),
converting it to calendar time as UTC, then requesting the calendar time
be treated as local time and converted to a time_t. Then converting it to
calendar time as UTC again.
 
The second mktime() call and the gmtime_r() call shouldn't be there. If
you want local time, it's in tm_. If you want UTC, it's in gmcal. The
value in tm2/*tm_p is nonsense; it's had the timezone offset applied twice.
 
I can't see how this can work in any situation other than where local time
happens to be UTC (or possibly UTC+1 due to DST which is being ignored).
seeplus <gizmomaker@bigpond.com>: Oct 13 05:31PM -0700

On Wednesday, October 14, 2015 at 12:47:41 AM UTC+11, JIE SHI wrote:
> Dear all,
 
> The program '[5668] CAS HYDRO VS2010.exe: Native' has exited with code 1 (0x1).
 
For a small C++ console program this usually indicates that the program has done it's stuff but disappeared off the screen before you could see it, and you just need to put a cin >> at the exit point to stop execution there so you can view what happened.
 
However CAS-HYDRO appears to be a program to check water quality and the
affect /cough/ of climate change, and it would appear that a "model" would be
VERY large and complex as it seems to produce graphs etc, so would likely
need various dependencies or .dlls you might not have included.
 
However these should get picked up by the compiler.
Is there any help from the source code supplier?
 
You need to use a debugger, or insert messages in your code "#have reached this
point X".
You received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page.
To unsubscribe from this group and stop receiving emails from it send an email to comp.lang.c+++unsubscribe@googlegroups.com.

No comments: