Results 1 to 2 of 2

Thread: Memory Allocation in C and Java

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1

    Default Memory Allocation in C and Java

    Hello Everyone, I am a beginner and I am working on my first freelance project. I want to know which programming language is good for memory allocation between C and java? Yesterday I search on google to find it and According to this post, In order to do memory allocation in C, functions like malloc(), calloc(), etc. can be used but there is no ‘new’ keyword in C. Java supports threading but not sure about Java programming. Can anyone know about this?

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Memory Allocation in C and Java

    This is an extremely basic question, and it seems to me that you need to learn a lot more about programming before you are ready for a freelance project.

    C and Java are completely different languages, both in concept and in use. C is a compiled language, most Java implementations are interpreted code at run time or use a just-in-time byte code compiler.

    C is a functional programming language, based on data structures, pointers, and function calls. In C, you must allocate and manage memory using the low level calls malloc, calloc, realloc, free, etc. If every call to allocate memory is not matched with a call to free it, you will have a memory leak. If you try to use a pointer to memory before you allocate it or after you free it, your program will crash. C has no protection to ensure that you do not access memory beyond the end of an array or overwrite memory that is being used by some other data structure.

    Java is an object-oriented language. You can use it for functional programming, but most Java programs are based on using object classes and their methods. Objects communicate with each other by calling each other's methods. Variables that store data for instances of objects are hidden inside the objects and can only be accessed through member functions. Java implements a system of "garbage collection" for object instances. If the memory management system sees that an object is no longer being used (referenced) by any other object, then it is removed and put into the garbage. When garbage collection occurs, the memory used by that object instance is recovered and can be used for allocating another object instance.

    For you, the choice of which language you use depends on the nature of your project. If you have no experience at all, I don't think you should use either of them, but instead use a language like Python, which is much more friendly to beginners.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Dynamic Memory Allocation
    By Atomic_Sheep in forum General Programming
    Replies: 2
    Last Post: 18th August 2013, 12:19
  2. memory allocation problem
    By marc2050 in forum Newbie
    Replies: 7
    Last Post: 23rd May 2011, 10:05
  3. Widget Memory Allocation
    By ArlexBee-871RBO in forum Qt Programming
    Replies: 5
    Last Post: 9th May 2010, 20:51
  4. QDrag : memory allocation
    By kghose in forum Qt Programming
    Replies: 1
    Last Post: 14th August 2008, 23:57
  5. limit memory allocation
    By magland in forum General Programming
    Replies: 10
    Last Post: 23rd March 2007, 10:21

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.