Thread: Storing data in an arbitrarily large data type on the stack

  1. #16
    Registered User
    Join Date
    Jan 2016
    Posts
    43
    The problem was clearly outlined in the first post.
    qsort() sorts array, arrays of structs, but it won't sort "anything". For example lists. Instead of trying to fudge this problem I implemented my own sorting algorithm in place. The algorithm does some other things too.
    Yes there is nothing wrong with bubble sort!

  2. #17
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    Now when I repeatedly said that I don't wish to specify a datatype for the storage explicitly, why am I going to make things more complicated and bundle a whole load them in a union instead?
    The only reason a union was suggested was because you specifically said earlier, "I want to be able to store it anywhere on the stack instead of using malloc or dynamic allocation on the heap (don't ask)." It is easy to write a generic swap with memcpy(); it's harder to do without malloc() and also still accommodate mostly arbitrary data types. That is why you are getting inconvenient suggestions. I'm sorry to tell you that it's much easier to just use malloc() in your implementation. Anything else is going to be even more work than that.
    Last edited by whiteflags; 08-05-2018 at 06:26 PM.

  3. #18
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    A third possible solution might be to use static keyword memory; but, this only avoids malloc() because it still uses the memory heap on most implementations.

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help managing large amounts of data and generating data from it
    By jakethehake in forum C++ Programming
    Replies: 0
    Last Post: 12-01-2009, 06:59 AM
  2. Data structure for storing serial port data in firmware
    By james457 in forum C Programming
    Replies: 4
    Last Post: 06-15-2009, 09:28 AM
  3. Replies: 3
    Last Post: 02-26-2008, 02:12 PM
  4. [Large file][Value too large for defined data type]
    By salsan in forum Linux Programming
    Replies: 11
    Last Post: 02-05-2008, 04:18 AM
  5. storing abstract data on a stack?
    By cppn00b in forum C++ Programming
    Replies: 4
    Last Post: 02-06-2005, 05:27 AM

Tags for this Thread