8

I just need one character that I can set in character arrays indicating that a particular location or a series of locations are free and available for storing data.

I need this because I am making a simple memory pool and need to reset freed blocks and indicate them as free.

Any help would be appreciated.

angryInsomniac
  • 829
  • 2
  • 13
  • 27
  • 6
    In short, no. There are better ways of managing memory than relying on a particular value not being used. –  Mar 17 '13 at 18:08
  • Cool, thanks, I just needed to confirm that. – angryInsomniac Mar 17 '13 at 18:09
  • Why is this question voted down? It is valid question. – Caesar Mar 17 '13 at 18:09
  • I believe I asked people in the Lounge and someone started a flame war on my perfectly valid query. – angryInsomniac Mar 17 '13 at 18:10
  • You could use something like character stuffing to distinguish between valid data and delimiters: http://harsha1988.blogspot.it/2008/01/character-stuffing.html – BlackBear Mar 17 '13 at 18:11
  • To what end ? I could still never be sure if whatever is in that particular char is actual information or the junk value I set. – angryInsomniac Mar 17 '13 at 18:13
  • Never is such a bad term. With a large population base and a large application base, there is a chance that all the ASCII values are used by one or more programs. – Thomas Matthews Mar 17 '13 at 18:14
  • 2
    So, I am guessing I will have to resort to a block descriptor that tells whether a block is valid or not. – angryInsomniac Mar 17 '13 at 18:15
  • 1
    You could use some appropriate characters: SOH, STX, ENQ, DC1, DC2, DC3, DC4, SYN, FS, GS, RS for message control. – Thomas Matthews Mar 17 '13 at 18:19
  • 3
    @angryInsomniac your comment in a since-deleted answer *"the char array can store data other than char, so it is entirely possible that [any char] shows up somewhere"* seems to invalidate your entire question. Why are you asking for an unused char if it's entirely possible that any char could be used? – Drew Dormann Mar 17 '13 at 18:21
  • @DrewDormann There are codes that are used by the systems memory manager to indicate unallocated memory, like CDCDCD shows up whenever a new unallocated block is made, I was looking for something similar. – angryInsomniac Mar 17 '13 at 18:29
  • Nope, `0xCDCDCDCD` is only used to help finding uninitialized variables in debug builds with Visual Studio. – Synxis Mar 17 '13 at 18:31
  • 1
    @angryInsomniac Writing `CDCDCDCD` would help **people** see that a block is likely unallocated, but it would be **incorrect** for any code to look for `CDCDCDCD` to determine if a block is unallocated. It appears that you misinterpreted that practice, and are now trying to reproduce that misinterpretation. – Drew Dormann Mar 17 '13 at 18:32
  • @DrewDormann Cool, I didn't know that 0xCDCDCDCD was only for debug builds. I will go with an alternative solution then, thanks. – angryInsomniac Mar 17 '13 at 18:34

3 Answers3

4

All ASCII code points are used for characters, but there are plenty of Unicode code points that are guaranteed to not be characters, for example U+FFFF.

I'm not sure of what you would do with this information, though. While the code point is not a valid character you can construct strings that include it. Those strings would not be legal in Unicode, but you seem to imply that you can store any data, not just Unicode text.

Joni
  • 108,737
  • 14
  • 143
  • 193
2

While this is not the best way to do, if you must than I would use bell key because I have never see anyone use it in my life.

The bell is 007 in oct.

enter image description here

Caesar
  • 9,483
  • 8
  • 40
  • 66
  • 8
    No! Not the bell character! What if I want to make a ding sound in my terminal? – Xymostech Mar 17 '13 at 18:14
  • I cant, the char array can store data other than char, it is just a pool of data , so it is entirely possible that 007 oct shows up somewhere as valid data (maybe an int value) – angryInsomniac Mar 17 '13 at 18:14
  • @Xymostech If you do than you will be the first person I have ever seen that uses it. – Caesar Mar 17 '13 at 18:14
  • 2
    The BEL character is so common that it has an escape code in most programming languages: `\a`. And unlike the form feed escape `\f` many people actually use it: http://stackoverflow.com/a/4060616/318758 http://stackoverflow.com/a/10075175/318758 http://stackoverflow.com/a/12919505/318758 – Joni Mar 17 '13 at 20:07
1

As was previously mentioned, ASCII code points are all used for characters; however, you can easily limit your strings so as not to use certain characters in ASCII. For example, the vertical tab is rarely used in any strings for normal files; therefore, you could demand that your character arrays all exclude the character vertical tab and use such a character to do what you are asking. The same can be done for UNICODE; although, as previously mentioned, it does have some reserved non-character codes.

Flayneorange
  • 228
  • 1
  • 9