Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Xiachunyi

C/C++: Making room for more characters and more

This topic is 5220 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, I am at this moment, trying to create an emulator command line for a 68k computer that is going to be built for my highschool senior project. As of right now I am programming the emulator in Windows just to evaluate the aesthetics of the command line. My question is, does this look okay for allocated and de-allocating memory to make room for user-input. This is for if the user presses the return key.
...
                    //Add a return to the user string

                    strcpy(hold, user); //Copy to temp location

                    delete [] user; //Delete source character array

                    user=new char [strlen(hold)+1]; //Allocate new size "+1 entry" and plus 1 for null terminator

                    strcpy(user, hold); //Copy temp location''s contents to source character array

                    delete [] hold; //Delete temp character array

                    hold=new char [strlen(user)+1]; //Allocate new size for use next time

                    strcat(user,"\r"); //Attach new character to user string contents

...
I know I will have to eventually learn how to create these functions from scratch but that is for later. Another Question: On a command line, will be alright if I used special keywords such as "Exec", "Help", "Play", and so on without violating any copyright laws? These seem, to me, universal but I''m not sure since people like to sue. Another Question: Say for example you have a row of memory cells. The first few grids are occupied by memory that is always resident and the rest is free for all. If a program allocates memory in say cells 60-70 and another program allocates memory for cells 71-90, will the first program''s, if it allocates memory in more cells so that its memory address encompasses 60-70 and 91-110, memory be fragmented? Thank you very much.

Share this post


Link to post
Share on other sites
Advertisement
Well, it will probably work, but in C++ it is a lot easier to use std::strings
2. Keywords cannot be copyrighted, an entire program can, but simple words can not.
3. Memory fragmentation means that there are lots of small ''holes'' of free memory. For example if program2 releases it''s memory. There are lots of studies on avoiding fragmentation, just google if you are interested.

Share this post


Link to post
Share on other sites
Thank you very much for your quick post. Also would it be alright if I recorded your message because I have to keep a journal of anything that I do for senior project.

Thank you again.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!