473,508 Members | 2,140 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Why does C++ program run differently on VxWorks?

I wrote many classes. In a class, there is a member variable which is
declared as char szMTreeBuf[4096]. On both Windows XP and VxWorks, it
cannot work. Then I try to declare the member variable as static char
szMTreeBuf[4096], it can work again. But when add some other function
codes, it cannot run normally. I modify the class delearation, and
change szMTreeBuf member variable to be local variable. Again it can
run now.

Why does C++ program run differently on VxWorks?

OS: VxWorks 5.5.1
Memory: 16M

Jul 12 '06 #1
5 4688

Allen wrote:
I wrote many classes. In a class, there is a member variable which is
declared as char szMTreeBuf[4096].
This would imply that each instance of the class has a szMTreeBuff
member (part of relationship). This is valid c++.
On both Windows XP and VxWorks, it
cannot work. Then I try to declare the member variable as static char
szMTreeBuf[4096], it can work again.
Big difference - this would imply that the szMTreeBuff member is shared
between all instances of the class of which the member is a part. Also
valid c++.
But when add some other function
codes, it cannot run normally. I modify the class delearation, and
change szMTreeBuf member variable to be local variable.
Local? (as in not a member anymore...)
Again it can run now.

Why does C++ program run differently on VxWorks?
There are many reasons for this. Do you use the same platform? You
certainly use a different compiler (I'm assuming). I've found that
Windows are more leniant than VxWorks wrt. enforcing hardware traps
when one makes serious mistakes. I must mention that changing where the
buffer is stored in memory has nothing to do with your problem (I
think). This only highlights (in all probability) another problem, as
the memory layout of the program may differ drastically considering the
changes that you've made. I suggest you to induce the problem by
allocating the applicable buffer in a way that induces the problem (as
I understand you, make it part of a class instance - non-static
member): BTW. you may consider getting rid of the horrible sz prefix...
What does is stand for, size? ;-)

class x_c
{
private:
char buff_[1000]; //part of :-)
}

If this now induces the problem, good - leave it that way as it is not
the problem itself. Note that if buff is used as a string, it may
become a problem (as it is not NULL terminated). Also note that when
you copy into buff, to not over-index. You may also use a vector - but
before you do that - stick to one thing - induce the problem and try to
find it - good luck. You seem in over your head.

Werner
>
OS: VxWorks 5.5.1
Memory: 16M
Jul 12 '06 #2
I think it depends on:
1) Where is the instance of the class created? stack or free storage?
2) If the instance is created on stack, is there enough stack size for
a process on target OS platform?
3) Is there enough memory for *static char szMTreeBuf[4096]* ? Because
this declaration leads to allocate memory on text section of a process,
after you add some function codes, these codes take some memery, in
result there maybe not enough memory to allocate 4096 chars.

Allen wrote:
I wrote many classes. In a class, there is a member variable which is
declared as char szMTreeBuf[4096]. On both Windows XP and VxWorks, it
cannot work. Then I try to declare the member variable as static char
szMTreeBuf[4096], it can work again. But when add some other function
codes, it cannot run normally. I modify the class delearation, and
change szMTreeBuf member variable to be local variable. Again it can
run now.

Why does C++ program run differently on VxWorks?

OS: VxWorks 5.5.1
Memory: 16M
Jul 12 '06 #3

Forest wrote:
I think it depends on:
1) Where is the instance of the class created? stack or free storage?
Good point.
2) If the instance is created on stack, is there enough stack size for
a process on target OS platform?
Especially in vxWks...
3) Is there enough memory for *static char szMTreeBuf[4096]* ? Because
this declaration leads to allocate memory on text section of a process,
after you add some function codes, these codes take some memery, in
result there maybe not enough memory to allocate 4096 chars.
Now that you mention - the program stops working when he allocates in
as part of an instance (and works if he creates it as part of class -
static). If he creates enough instances, he may run out of either stack
or heap, depending on where he creates the class or sequence of classes
(16M memory does seem skimpy compared to Windowzzz).

W

Jul 12 '06 #4
"Allen" <ch****@naritech.cnwrote in message
news:11**********************@b28g2000cwb.googlegr oups.com...
>I wrote many classes. In a class, there is a member variable which is
declared as char szMTreeBuf[4096]. On both Windows XP and VxWorks, it
cannot work. Then I try to declare the member variable as static char
szMTreeBuf[4096], it can work again. But when add some other function
codes, it cannot run normally. I modify the class delearation, and
change szMTreeBuf member variable to be local variable. Again it can
run now.

Why does C++ program run differently on VxWorks?

OS: VxWorks 5.5.1
Memory: 16M
You say it cannot run normally. What type of error do you get? Stack
overflow? Memory allocation?

One thing you might try is forcing it to use dynamic memory.

char* szMTreeBuf;

and in the constructor or initializaer
szMTreeBuf = new char[4096];

I suspect that will probably work.

It may also work the way you have it if you increase the stack size, you'll
have to look for settings for that in your compiler(s).
Jul 12 '06 #5
Forest wrote:
I think it depends on:
1) Where is the instance of the class created? stack or free storage?
There is an only single global instance of the class.
2) If the instance is created on stack, is there enough stack size for
a process on target OS platform?
Yes, I also think so. But Why cannot work on Windows XP? I will try to
change the
stack size in VC++ compiler.
3) Is there enough memory for *static char szMTreeBuf[4096]* ? Because
this declaration leads to allocate memory on text section of a process,
after you add some function codes, these codes take some memery, in
result there maybe not enough memory to allocate 4096 chars.
How to adjust text section size? If I change the declaration to be
static int buffer[1024].
Will this declaration allocate memory on data section?

Jim Langston wrote:
One thing you might try is forcing it to use dynamic memory.

char* szMTreeBuf;

and in the constructor or initializaer
szMTreeBuf = new char[4096];

I suspect that will probably work.
Our HW has not MMU, therefore we do not allow dynamic memory
allocation.

Jul 13 '06 #6

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

Similar topics

0
1392
by: Oracle | last post by:
After searching through the archives, I've no been able to find much information on running python on VxWorks. In fact, most all of the links (email addresses and URLs) are now dead. Not to...
24
3765
by: David Mathog | last post by:
If this: int i,sum; int *array; for(sum=0, i=0; i<len; i++){ sum += array; } is converted to this (never mind why for the moment):
4
5951
by: Songling | last post by:
Hi, Anybody knows if SO_RCVBUF option can be applied to VxWorks' setsockopt() for raw socket? If yes, what's the default value? Thanks! Songling
126
4196
by: ramyach | last post by:
Hi friends, I need to write a parallel code in 'C' on the server that is running SGI Irix 6.5. This server supports MIPS Pro C compiler. I don't have any idea of parallel C languages. I looked...
0
1241
by: Miki | last post by:
Hello All, I saw some old posts about vxWorks port of Python. Is there someone who can give me pointers to more recent efforts of porting Python to wxWorks? Thanks, Miki
1
5530
by: yamitmehta | last post by:
When I compile to code using g++arm of VxWorks 5.5 and put it on my board i get the follwing undefined symbols:- Cpool and Csingleton are template classes. CPool has the static member...
1
2055
by: askcq | last post by:
Can anyone help on this ?? how to pass String as Argument while creating TASK in VXWORKS
32
2523
by: jhc0033 | last post by:
Interesting article I came across on Slashdot: http://developers.slashdot.org/developers/08/07/10/213211.shtml They are using C at JPL to program Mars Lander and just about everything now! Not...
1
4115
by: lovecreatesbeauty | last post by:
Are these macros defined in Makefile or by some environment which can detect the platform types? /* common code here */ #ifdef LINUX /* other os spefic code */ #elif defined VXWORKS
0
7228
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7393
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7058
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5635
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5057
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4715
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3206
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3191
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
769
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.