Thread: C/C++ Memory Calls!

  1. #1
    Registered User
    Join Date
    Oct 2002
    Posts
    12

    Lightbulb C/C++ Memory Calls!

    Hey!

    Im going through some documentation about a previous software that needs to be ported and updated. It uses C with no C++ code. The new version is supposed to be written in C++.

    The app uses some memory calls to store some image data. What is best, use old malloc, realloc instead of using C++ calls like "new TYPE" etc: Whats good and what bad about using a C++ style and skip the old memory calls and use some new "new","delete" calls to work with memory.

    Thanks!


    Joda

  2. #2
    Registered User
    Join Date
    Oct 2002
    Posts
    12
    My software is using lots of structures to store all of the data. One structure keeps a track of cache, x, y. Is it better to implement the variables as separate ones in my new C++ class?

    Is the C++ mem calls faster?



    Thanks for the reply!

    Joda

  3. #3
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    Originally posted by Joda
    My software is using lots of structures to store all of the data. One structure keeps a track of cache, x, y. Is it better to implement the variables as separate ones in my new C++ class?
    Depends on your app and how it works I suppose

    Originally posted by Joda

    Is the C++ mem calls faster?
    Some C++ implementations use malloc & free via new and delete to allocate memory.......all new does is cast the memory (mybe allocated by malloc) and call construtors...But if you are implementing classes, you need new to call the construtors - rather difficult to do yourself.....so in this case, stick with new IMO

  4. #4
    Registered User
    Join Date
    Oct 2002
    Posts
    12
    Here's my app:

    First I do init some stuff and allocate some memory using a malloc() method. Then I load in image data for each frame in my animation.

    When I playback and cache the frames the app calls a realloc and puts in my imagedata.

    The software is completely written with structures and methods.

    So is it a good idea to setup a class that is working with all of the data? Say that Im using an array of "dataFrames" to store all of the image information? the problem is that my app is very well done and the mem calls works great and I dont want to miss any speed.

    Thanks!

    /joda

  5. #5
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    Originally posted by Joda
    Here's my app:

    First I do init some stuff and allocate some memory using a malloc() method. Then I load in image data for each frame in my animation.

    When I playback and cache the frames the app calls a realloc and puts in my imagedata.

    The software is completely written with structures and methods.

    So is it a good idea to setup a class that is working with all of the data? Say that Im using an array of "dataFrames" to store all of the image information? the problem is that my app is very well done and the mem calls works great and I dont want to miss any speed.

    Thanks!

    /joda
    Well the C memory functions are still perfectly leagal under c++, but as said you will need to cast and not use constructors

  6. #6
    Registered User
    Join Date
    Oct 2002
    Posts
    12
    so just one last question is it ok to use a structure inside a class? I want to modify as little as possible of the code...

    /Joda

  7. #7
    Registered User moi's Avatar
    Join Date
    Jul 2002
    Posts
    946
    Originally posted by Joda
    so just one last question is it ok to use a structure inside a class? I want to modify as little as possible of the code...

    /Joda
    woah there. back up a second; why are you doing this in the first place?
    hello, internet!

  8. #8
    KingoftheWorld
    Guest

    Re: C/C++ Memory Calls!

    Originally posted by Joda
    Hey!

    Im going through some documentation about a previous software that needs to be ported and updated. It uses C with no C++ code. The new version is supposed to be written in C++.

    The app uses some memory calls to store some image data. What is best, use old malloc, realloc instead of using C++ calls like "new TYPE" etc: Whats good and what bad about using a C++ style and skip the old memory calls and use some new "new","delete" calls to work with memory.

    Thanks!


    Joda
    If your purpose to reimplement the project for reuse and easy maintenant later, then just start to reimplement some less important C structs(such as I/O utility) in C++ classes. For those efficient C functions(worked well in previous version) leave them alone for now and they become general functions (not class member functions) in your project. You can make calls these general function into your class's member functions to do intended
    computation or processing needs.
    Later on, you still have chances to continue porting completely your project into C++ dealing with some critical parts of your current project related to code efficiency after investigating and scaling the code efficiency between C malloc() etc.. and C++ New
    operator..........
    I assume that the compiler you use for your project is support
    for C and C++ such as you can include boht the stdio.h and iostream.h.
    Hope you get an idea!

    KingoftheWorld






    functions

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problems with shared memory shmdt() shmctl()
    By Jcarroll in forum C Programming
    Replies: 1
    Last Post: 03-17-2009, 10:48 PM
  2. Shared Memory - shmget questions
    By hendler in forum C Programming
    Replies: 1
    Last Post: 11-29-2005, 02:15 AM
  3. Memory allocation and deallocation
    By Micko in forum C++ Programming
    Replies: 3
    Last Post: 08-19-2005, 06:45 PM
  4. Pointer's
    By xlordt in forum C Programming
    Replies: 13
    Last Post: 10-14-2003, 02:15 PM
  5. Managing shared memory lookups
    By clancyPC in forum Linux Programming
    Replies: 0
    Last Post: 10-08-2003, 04:44 AM