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 - Feature suggestion: PointerExist(ptr)
Page 1 of 1

PostPosted: Sun Mar 04, 2001 9:14 am
by darwin
If I try to access a pointer that does not exist - p=malloc(3);p[4]=4; I'll get an error message. Couldn't you add a function that checks if the pointer exists (was allocated). Or a function that find's out how long the array is (count(ptr)).

http://www.strange-phenomenom.de/index.php3

PostPosted: Sun Mar 04, 2001 11:29 am
by guy
Just check that the value of the pointer is not NULL (0):

p = malloc(500) ;

if (p!=0) {
p[4] = 2 ;
}



Guy

PostPosted: Sun Mar 04, 2001 2:49 pm
by wolfgang
Hello Guy,

I think you two were talking about two different things.
In Darwin's example the array will be allocated correctly, but he tried to access an element outside the allocated range (allocated size: 3, but accessing element no. 5 (index 4)).

In your case, you only check if the allocation itself was successful. BTW, while your code is theoretically correct, I found out that PocketC (both the WindowsCE version and the Palm version) will crash if you try to allocate something that is far too large. (for WindowsCE I am talking about V2, not V3; Platform is an LG Phenom HPC, WindowsCE 2.0). This is really annoying because I wanted to use subsequently larger mallocs to find out the memory available for my programs. Since this risks to crash my program altogether, I preferred to renounce this feature in my published programs.

Wolfgang

PostPosted: Sun Mar 04, 2001 2:57 pm
by guy
How about:

iSpaceINeed = 3 ;

p = malloc(iSpaceINeed) ;

if (p!=0) {
if (4 < (iSpaceINeed -1)) {
p[4] = 4 ;
}
}

The amount of memory to be allocated will always be a variable or a constant, or an expression that can be assigned to a variable. It's just a matter of the program knowing what it's done in the past.

I wasn't aware that you could crash malloc with large requests. There were problems in PocketC V1, but I thought Kevin had nailed down all the memory problems.


Guy

PostPosted: Sun Mar 04, 2001 3:12 pm
by darwin
Of course there are solutions by "our" side - another could be to safe the array's lenght always in [0]. But that is not what I asked for. If I have an array, there should be a method to find out how long it is without writing down the lenght of it somewhere...

http://www.strange-phenomenom.de/index.php3

PostPosted: Mon Mar 05, 2001 7:39 am
by guy
I assume that Kevin must store the size of the allocated memory block somewhere because it's needed when the memory is freed.

The structure that contains the information returned by typeof() probably contains it.

Maybe a length() function would be nice.

If you're used to writing in "real" C then you tend to look out for memory problems anyway.


Guy