Reg memory error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • shariquehabib
    New Member
    • Oct 2006
    • 22

    Reg memory error

    Hi All,

    I m creating one exe using C programing and i m facing one issue in this.
    I defined an array which size was 1024 (like SortOnPrimarySo l[1024] )Now i want to increase this size to more than this 1024.

    While increasing the size as more than 1035, the exe is creating but while execiting this exe, its giving me memory reference error.
    If i will decrease this size to 1030 and again create this exe and run this exe then it is working fine.

    Can any one let me know what is the prob while i m giving array size as more than 1030???? and why?? is thr any limitation ??
    How can i overcome from this issue???

    Plaese let me know.

    Thanks in advance,
    Sharique
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    That is rather dependent on the platform you are using. However if this variable is being placed on the stack (has auto scope) then you need to change you code structure. It is inadvisable to put so much data on the stack.

    Giving the array count doesn't really help without knowing the type, how much data are you actually trying to allocate?

    There is no syntactic reason for an array to be limited to 1030 entries, the limiting factor is memory.

    Comment

    • weaknessforcats
      Recognized Expert Expert
      • Mar 2007
      • 9214

      #3
      Originally posted by shariquehabib
      While increasing the size as more than 1035, the exe is creating but while execiting this exe, its giving me memory reference error.
      If i will decrease this size to 1030 and again create this exe and run this exe then it is working fine.

      Can any one let me know what is the prob while i m giving array size as more than 1030???? and why?? is thr any limitation ??
      How can i overcome from this issue???
      You create your array on the heap whwere you can specify the number of elements at run time.
      To expand the array:
      1) create a new array on the heap of the new size
      2) copy the original array into new array
      4) delete the pointer to the original array
      5) put the address of the new array into the pointer to the original array

      I would do this inside a function that takes the address of the pointer tio the original array. Here is one assuming an array of int:
      [code=c]
      void ExpandArray(int r** arr, int newsize)
      {
      int* temp = new int[newsize]
      //TODO: copy arr array to temp array
      delete *arr; //delete original array
      *arr = temp; //put new array address into pointer to original array
      }
      [/code]

      When the function returns the original array has been expanded.

      Comment

      Working...