473,387 Members | 1,585 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Memory inizialization 2

Hi, again

I have readed the answare, I don't like it.
What do you think about this solutions? obiusly it works
only for dynamic allocated data.

class{
int a1;
..
...
int a100
char v1[100]
...
char v100[100]

void *operator new(size_t size){
void *ptr=malloc(size);
memset(ptr,0,size);
return ptr;
}
}

MarcoC
Jul 22 '05 #1
4 1024
"mcassiani" <mc*******@virgilio.it> wrote in message news:rrEAc.492860
I have readed the answare, I don't like it.
What do you think about this solutions? obiusly it works
only for dynamic allocated data.

class{
int a1;
..
..
int a100
char v1[100]
...
char v100[100]

void *operator new(size_t size){
void *ptr=malloc(size);
memset(ptr,0,size);
return ptr;
}
}


Remember to provide operator delete too as the system operator delete might
not call free.

It works for objects created on the heap, but what about objects created on
the stack?

Jul 22 '05 #2
On Fri, 18 Jun 2004 16:07:51 GMT, "mcassiani" <mc*******@virgilio.it>
wrote:
Hi, again

I have readed the answare, I don't like it.
What do you think about this solutions? obiusly it works
only for dynamic allocated data.

class{
int a1;
..
..
int a100
char v1[100]
...
char v100[100]

void *operator new(size_t size){
void *ptr=malloc(size);
Instead:
void* ptr = ::operator new(size);
memset(ptr,0,size);
return ptr;
}
What about operator new[]?
}


Again, setting all bytes to 0 won't necessarily work for all POD
types, particularly for doubles (and theoretically for pointers too).
How about this:

class test
{
private:
struct data_t
{
int mem1;
double mem2;
char mem3;
double mem4[50];
} data;
public:
test()
:data(data_t()) //zero initialises data
{
}
};

Tom
--
C++ FAQ: http://www.parashift.com/c++-faq-lite/
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
Jul 22 '05 #3

"tom_usenet" <to********@hotmail.com> ha scritto nel messaggio
news:44********************************@4ax.com...
On Fri, 18 Jun 2004 16:07:51 GMT, "mcassiani" <mc*******@virgilio.it>
wrote:
Hi, again

I have readed the answare, I don't like it.
What do you think about this solutions? obiusly it works
only for dynamic allocated data.

class{
int a1;
..
..
int a100
char v1[100]
...
char v100[100]

void *operator new(size_t size){
void *ptr=malloc(size);


Instead:
void* ptr = ::operator new(size);
memset(ptr,0,size);
return ptr;
}


What about operator new[]?
}


Again, setting all bytes to 0 won't necessarily work for all POD
types, particularly for doubles (and theoretically for pointers too).
How about this:

class test
{
private:
struct data_t
{
int mem1;
double mem2;
char mem3;
double mem4[50];
} data;
public:
test()
:data(data_t()) //zero initialises data
{
}
};

Tom
--
C++ FAQ: http://www.parashift.com/c++-faq-lite/
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html


I have tested the binary double composition for x86 processor and HP-PARISC
and 0 init
work well.

Jul 22 '05 #4
On Sat, 19 Jun 2004 07:33:47 GMT, "mcassiani" <mc*******@virgilio.it>
wrote:
I have tested the binary double composition for x86 processor and HP-PARISC
and 0 init
work well.


Yes, in practice it works on many platforms, but if you leave the bug
in some code that's meant to be portable, it may come back to bite
you. If it's not meant to be portable (and the non-portable parts are
clearly marked), you may be ok.

Tom
--
C++ FAQ: http://www.parashift.com/c++-faq-lite/
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
Jul 22 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Andreas Suurkuusk | last post by:
Hi, I just noticed your post in the "C# memory problem: no end for our problem?" thread. In the post you implied that I do not how the garbage collector works and that I mislead people. Since...
4
by: Frank Esser | last post by:
I am using SQL 8 Personal edition with sp2 applied. I set the max server memory to 32MB and leave the min server memory at 0. When my application starts hitting the database hard the memory usage...
32
by: John | last post by:
Hi all: When I run my code, I find that the memory that the code uses keeps increasing. I have a PC with 2G RAM running Debian linux. The code consumes 1.5G memory by the time it finishes...
4
by: Franklin Lee | last post by:
Hi All, I use new to allocate some memory,even I doesn't use delete to release them. When my Application exit, OS will release them. Am I right? If I'm right, how about Thread especally on...
9
by: Mike P | last post by:
I know everything about reference counting and making sure you don't have large objects lying around. I have also profiled my app with multiple tools. I know about the fact GC collects memory but...
12
by: Jeremy | last post by:
Hi all, I'm getting very confused about how DB2 uses shared memory and I wonder if someone could clarify matters for me, please ? We are running 32bit DB2 V7.2 FP9 under AIX 4.3.3 on a machine...
22
by: xixi | last post by:
hi, we are using db2 udb v8.1 for windows, i have changed the buffer pool size to accommadate better performance, say size 200000, if i have multiple connection to the same database from...
7
by: Jon Trickey | last post by:
We migrated to 8.1 from 7.2 this weekend. Everything ran ok over the weekend, but we have a light user load then (about 200 users.) Today when we had close to 600 users connecting and running...
5
by: kumarmdb2 | last post by:
Hi guys, For last few days we are getting out of private memory error. We have a development environment. We tried to figure out the problem but we believe that it might be related to the OS...
1
by: Jean-Paul Calderone | last post by:
On Tue, 22 Apr 2008 14:54:37 -0700 (PDT), yzghan@gmail.com wrote: The test doesn't demonstrate any leaks. It does demonstrate that memory usage can remain at or near peak memory usage even after...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.