Dynamic Memory allocation example

You must understand the Game Editor concepts, before post here.

Dynamic Memory allocation example

Postby Fojam » Fri Mar 08, 2013 9:50 pm

So I was bored one day, and I was like "hey why don't I mess around with game editor a bit?" So I decided to make a String object, (which was one of my major beefs with game editor is the fact you cant make classes) and so I created a struct called string

I made it so that it dynamically allocates memory for the string. only problem is, I think I found a weird bug in game-editor with the strlen(char*) function

I made two examples of strings. one using linked memory addresses, and the other using a dynamically resizing array.

Please tell me what you think and what is the problem with strlen (if you know)

Edit: to clarify, I am not "back". I just thought I would make a little utility in c, and see if it worked in game-editor
Attachments
DynamicMem.zip
(213.6 KiB) Downloaded 134 times
CLICK TO GIVE ME POINTS

My Latest Projects:
Super Smash Bros: viewtopic.php?f=6&t=12307 PLEASE help by making sprites!
User avatar
Fojam
 
Posts: 513
Joined: Thu Mar 19, 2009 10:02 pm
Location: under your bed!!!
Score: 69 Give a positive score

Re: Dynamic Memory allocation example

Postby skydereign » Sat Mar 09, 2013 2:08 am

Fojam wrote: I think I found a weird bug in game-editor with the strlen(char*) function

Normally in this kind of post you'd say what the problem you think you found is...
http://www.cplusplus.com/reference/cstring/strlen/ wrote:size_t strlen ( const char * str );

Get string length
Returns the length of the C string str.

The length of a C string is determined by the terminating null-character: A C string is as long as the number of characters between the beginning of the string and the terminating null character (without including the terminating null character itself).
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Dynamic Memory allocation example

Postby Fojam » Sat Mar 09, 2013 3:04 am

See that's the thing. I have no idea how to explain it! Just run it and watch it for a minute
CLICK TO GIVE ME POINTS

My Latest Projects:
Super Smash Bros: viewtopic.php?f=6&t=12307 PLEASE help by making sprites!
User avatar
Fojam
 
Posts: 513
Joined: Thu Mar 19, 2009 10:02 pm
Location: under your bed!!!
Score: 69 Give a positive score

Re: Dynamic Memory allocation example

Postby skydereign » Sat Mar 09, 2013 3:16 am

Fojam wrote:See that's the thing. I have no idea how to explain it!

You can at least explain the symptoms. Otherwise you wouldn't know it is a problem. How long must I stare at it? I switched the fps to 200 and watched it for a while, and nothing has changed.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Dynamic Memory allocation example

Postby Fojam » Sat Mar 09, 2013 12:32 pm

I meant to say calloc, but the bug is that random characters, a lot of time it will be text from the code, will flash after hello world. This happens on both of them.
CLICK TO GIVE ME POINTS

My Latest Projects:
Super Smash Bros: viewtopic.php?f=6&t=12307 PLEASE help by making sprites!
User avatar
Fojam
 
Posts: 513
Joined: Thu Mar 19, 2009 10:02 pm
Location: under your bed!!!
Score: 69 Give a positive score

Re: Dynamic Memory allocation example

Postby Fojam » Wed Mar 13, 2013 8:00 pm

Ah that was totally my bad! it's not a bug, I just forgot to null terminate the string.
CLICK TO GIVE ME POINTS

My Latest Projects:
Super Smash Bros: viewtopic.php?f=6&t=12307 PLEASE help by making sprites!
User avatar
Fojam
 
Posts: 513
Joined: Thu Mar 19, 2009 10:02 pm
Location: under your bed!!!
Score: 69 Give a positive score


Return to Advanced Topics

Who is online

Users browsing this forum: No registered users and 1 guest