Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7764699
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T14:58:51+00:00 2026-06-01T14:58:51+00:00

Note: when I say static string here I mean memory that can not be

  • 0

Note: when I say “static string” here I mean memory that can not be handled by realloc.

Hi, I have written a procedure that takes a char * argument and I would like to create a duplicate IF the memory is not relocatable/resizable via realloc. As is, the procedure is a ‘heavy’ string processor, so being ignorant and duplicating the string whether or not it is static will surely cause some memory overhead/processing issues in the future.

I have tried to use exception handlers to modify a static string, the application just exits without any notice. I step back, look at C and say: “I’m not impressed.” That would be an exception if I have ever heard of one.

I tried to use exception handlers to call realloc on a static variable… Glib reports that it can’t find some private information to a structure (I’m sure) I don’t know about and obviously calls abort on the program which means its not an exception that can be caught with longjmp/setjmp OR C++ try, catch finally.

I’m pretty sure there must be a way to do this reasonably. For instance dynamic memory most likely is not located anywhere near the static memory so if there is a way to divulge this information from the address… we might just have a bingo..

I’m not sure if there are any macros in the C/C++ Preprocessors that can identify the source and type of a macro argument, but it would be pretty dumb if it didn’t. Macro Assemblers are pretty smart about things like that. Judging by the lack of robust error handling, I would not be a bit surprised if it did not.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T14:58:52+00:00Added an answer on June 1, 2026 at 2:58 pm

    You may be able to detect ranges of memory and do some pointer comparisons. I’ve done this in some garbage collection code, where I need to know whether a pointer is in the stack, heap, or elsewhere.

    If you control all allocation, you can simply keep min and max bounds based on every dynamic pointer that ever came out of malloc, calloc or realloc. A pointer lower than min or greater than max is probably not in the heap, and this min and max delimited region is unlikely to intersect with any static area, ever. If you know that a pointer is either static or it came from malloc, and that pointer is outside of the “bounding box” of malloced storage, then it must be static.

    There are some “museum” machines where that sort of stuff doesn’t work and the C standard doesn’t give a meaning to comparisons of pointers to different objects using the relational operators, other than exact equality or inequality.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have a simple stored procedure that looks like this (note: this
Let's say that I have a class Foo: public class Foo { public static
I'm installing http://bitbucket.org/agr/ropemacs for my emacs. In README.txt it say: Note that rope and
The Django docs say this on the subject: Note also that Django stores signal
Here is what i have: a SQL CE database, that holds this Category table,
Say I have this in my class private static Stack<int> _cursorRefCounts = new Stack<int>();
I want to be able to write extension methods so that I can say:
Lets say I have this extention method: public static bool HasFive<T>(this IEnumerable<T> subjects) {
I have the following code that gets initialized as a static variable in a
Let's say you have the following code: string encoded=9,8,5,4,9; // Parse the encoded string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.