Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3368: Cannot modify header information - headers already sent by (output started at /includes/bbcode.php:472)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3370: Cannot modify header information - headers already sent by (output started at /includes/bbcode.php:472)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3371: Cannot modify header information - headers already sent by (output started at /includes/bbcode.php:472)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3372: Cannot modify header information - headers already sent by (output started at /includes/bbcode.php:472)
OrbWorks Community Forum • View topic - Out of memory using structs
Page 1 of 1

PostPosted: Sun Nov 10, 2002 8:52 pm
by stenci
Running the following code i get "Out of memory".
Where is my error?

struct st1{
int i;
string s;
};
struct st2{
string x;
struct st1 y;
};
struct st2 x;
int y;
main(){
alert("Ok");
}

Ciao
Stefano

PostPosted: Mon Nov 11, 2002 1:11 am
by BobWhite
It looks like you are trying to define st2 twice.
Try this:


struct st1{
int i;
string s;
};
struct st2{
string x;
struct st1 y;
};
st2 x;
int y;
main(){
alert("Ok");
}

;) Bob

Bob White WO3B
rwwhite@sbcglobal.net

PostPosted: Mon Nov 11, 2002 9:34 am
by guy
I believe that global structs are broken in PocketC.

Try using local variables, or allocate the struct using malloc() and settype() and a global pointer.



Guy
[url]mailto:pcform@pcform.net[/url]
http://www.pcform.net
PocketC CE API interface: http://www.networkdynamics.net/PCForm.html#library
PCForm and CE API forum: http://www.networkdynamics.net/forum

PostPosted: Mon Nov 11, 2002 5:01 pm
by KOU
>>It looks like you are trying to define st2 twice.
Well, it is right in PocketC. (not in real ANSI C)
Like guy said. There is a bug in global struct handling in PocketC

PostPosted: Tue Nov 12, 2002 7:52 am
by stenci
<blockquote id="quote"><font size="1" face="Verdana, Arial, Helvetica" id="quote">quote:<hr height="1" noshade id="quote"><i>Originally posted by guy</i>
<br />I believe that global structs are broken in PocketC.

Try using local variables, or allocate the struct using malloc() and settype() and a global pointer.
<hr height="1" noshade id="quote"></blockquote id="quote"></font id="quote">

What about the size of the malloc() for a struct containing variable size strings?
I guess the struct will contain just pointers to strings.
How big are pointers?
Will the garbage collection work well?

Or, if I will use char[] instead of string, is there any way to convert a char[] into a string?

Ciao
Stefano

PostPosted: Tue Nov 12, 2002 9:24 am
by guy
PocketC variables all take up the same amount of "room", and are runtime typed.

malloc() on PocketC allocates <b><i>variables</i></b> not bytes of memory. So to allocate memory for a struct containing five fields of any type you use:

ptr = malloc(5) ;

You then use the settype() function to set the type of each field (to int, float, char or string; use int for pointers). You cannot declare a pointer to a struct in PocketC, but you can declare a reference to a struct. In order to use the malloced struct in an easily readable way, you need to allocate the memory in the main() function, then pass the pointer to the struct down to subsiduary functions which receive it as a reference to a struct. Alternatively you can access the fields in the struct using array indexing notation, it looks like an array where each element can be of a different type.

If you malloc() memory for a string, you still ask for 1 memory location. You can put a string of any length into it.

A PocketC variable is actually a C++ class object. It contains a union of the three numeric types and a reference to a string header. The string header points to the string which can be shared (if you copy a string to another string, all that happens is the headers are updated and the string reference count is incremented (and the reference to the previous value of the target string is updated).


Where is st2 being defined twice in the original post? Has it been updated?





Guy
[url]mailto:pcform@pcform.net[/url]
http://www.pcform.net
PocketC CE API interface: http://www.networkdynamics.net/PCForm.html#library
PCForm and CE API forum: http://www.networkdynamics.net/forum

PostPosted: Wed Nov 13, 2002 7:30 am
by stenci
<blockquote id="quote"><font size="1" face="Verdana, Arial, Helvetica" id="quote">quote:<hr height="1" noshade id="quote"><i>Originally posted by guy</i>
<br />I believe that global structs are broken in PocketC.

Try using local variables, or allocate the struct using malloc() and settype() and a global pointer.
<hr height="1" noshade id="quote"></blockquote id="quote"></font id="quote">

Using global variables and a global pointer would be the easiest way.
Do I risk stack overflow using a big structure... or local variables are not on the stack (if sizeof() is not true memory size everything can happen)?

Ciao
Stefano

PostPosted: Wed Nov 13, 2002 8:54 am
by guy
I don't think you'll have a stack problem unless you start using really big structs. I don't know how PocketC allocates local variables, it would have to fit in with its pointer handling.

sizeof() doesn't exist in PocketC.

If you run out of memory the PocketC runtime displays a message box and falls over.

Another alternative is to store your structs in "real" memory rather than PocketC memory. The CEAPI library lets you allocate chunks of real memory and transfer PocketC variables (including structs and arrays) between real memory/real variables and PocketC memory/PocketC variables.


Guy
[url]mailto:pcform@pcform.net[/url]
http://www.pcform.net
PocketC CE API interface: http://www.networkdynamics.net/PCForm.html#library
PCForm and CE API forum: http://www.networkdynamics.net/forum