Thread: A memory leak

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Apr 2021
    Posts
    143
    It appears that you are using equality in your range-top comparison. That is, count <= MAX. You do the same thing in your fibonacci routine. This means it is possible to enter the array size limit as a valid value, but accessing that element of the array is not permitted - arrays go from 0 .. n-1, accessing array[n] is not permitted (although computing that address is valid).

    In C, it is "idiomatic" to use non-inclusive ranges in order to accommodate the zero-based nature of arrays. You might find your code "just works better" if you get used to thinking in terms of 0 <= x < max.

  2. #2
    Registered User
    Join Date
    May 2020
    Posts
    23
    Quote Originally Posted by aghast View Post
    It appears that you are using equality in your range-top comparison. That is, count <= MAX. You do the same thing in your fibonacci routine. This means it is possible to enter the array size limit as a valid value, but accessing that element of the array is not permitted - arrays go from 0 .. n-1, accessing array[n] is not permitted (although computing that address is valid).

    In C, it is "idiomatic" to use non-inclusive ranges in order to accommodate the zero-based nature of arrays. You might find your code "just works better" if you get used to thinking in terms of 0 <= x < max.
    Thank you for the excellent points. aghast. I know that in C, array indexing begins at zero. So I should have considered that when writing the "between" function. Lately, I'm programming in Racket, Common Lisp and OCaml.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. memory leak
    By *nick in forum Windows Programming
    Replies: 8
    Last Post: 09-17-2012, 06:15 PM
  2. Possible memory leak?
    By 127.0.0.1 in forum C Programming
    Replies: 21
    Last Post: 05-02-2011, 04:53 PM
  3. Replies: 2
    Last Post: 09-28-2006, 01:06 PM
  4. Is this a memory leak?
    By jasonhv in forum C++ Programming
    Replies: 5
    Last Post: 10-20-2005, 08:37 PM
  5. How is this a Memory Leak?
    By Cheeze-It in forum C++ Programming
    Replies: 4
    Last Post: 05-24-2002, 04:59 AM

Tags for this Thread