-1

Ok this might seem odd but please bear with me, I'm just a beginner. Over the past few days i have been trying to develop a general purpose hash function for maintaining an associative array with a hash table using all the best parts of hash functions like RS ,JS , ELF e.t.c to reduce hash collisions. but now the problem is even now to avoid a appreciable amount of collision i will have to use unsigned long values with atleast 6 digits to avoid collision.

Lets just assume i just need to map names of students to their marks.So i maintain an integer array for the marks.

Now back to my question.

The idea i thought of was to use these values as few lower order bits of of an actual memory address and then dynamically initialize memory large enough to store a integer for the marks obtained. This process is repeated for each new value added.

Now assuming i somehow managed to avoid all memory locations that would be reserved by the OS

Is there any viable way to dynamically initialize memory at an address we like rather than letting the new operator to initialize it and then return a pointer to that address location in C++. (i'm using gcc).

krish
  • 104
  • 1
  • 13

1 Answers1

0

It is platform-dependant. On Unix systems, you might try using mmap(). The Windows equivalent is VirtualAlloc(). But there is no guarantee since the address might already be in use.

Dinesh
  • 2,194
  • 3
  • 30
  • 52
  • I found this now - this might be useful http://stackoverflow.com/questions/10364582/can-i-allocate-a-specific-memory-address-using-pointers-in-c – Dinesh Jan 18 '14 at 15:53