malloc, new in a ISR, safe or not ? 
Author Message
 malloc, new in a ISR, safe or not ?

 Qian Zhong
 Department of Chemistry.
 UNC, Greensboro

[ malloc.new < 1K ]
Hi, folks:

I am writing a timer ISR, which will be called by a faster clock, at
every 5 ms. Any  one can help me clear some question ?

1. In a ISR for DOS, it should not call DOS function, because most DOS
function is not for re-entry, am I right or wrong ?
2. Some people said, malloc() family will call DOS function, so I should not
use malloc() in ISR, right or wrong ?
3. How about new and delete operator ? do they use any DOS function for a
DOS application ? can I use new or delete in a ISR ? As I understand,
both new and malloc family should be portable and system independent, but
do they actually call some DOS or Windows API functions ?

Thanks, please send me email.

Cheer

Qian



Wed, 22 Jul 1998 03:00:00 GMT  
 malloc, new in a ISR, safe or not ?

Quote:

> Hi, folks:

> I am writing a timer ISR, which will be called by a faster clock, at
> every 5 ms. Any  one can help me clear some question ?

> 1. In a ISR for DOS, it should not call DOS function, because most DOS
> function is not for re-entry, am I right or wrong ?

in timer ISR, if INDOS flag is not set, DOS function still can be called.

Quote:
> 2. Some people said, malloc() family will call DOS function, so I should not
> use malloc() in ISR, right or wrong ?

Under DOS, malloc will call DOS function to grow the heap if the free
heap space isn't enough, under Windows, malloc will call  windows to
grow heap. In many implementions, it is true.

Quote:
> 3. How about new and delete operator ? do they use any DOS function for a
> DOS application ? can I use new or delete in a ISR ? As I understand,
> both new and malloc family should be portable and system independent, but
> do they actually call some DOS or Windows API functions ?

  in some implementions, "new" maybe call "malloc", and "delete" will
call "free", as I said, DOS functions will be called under DOS, and
Windows API will be called under Windows.

  Note that many C runtime library functions are not re-enterable, so
it is dangerous to call them in ISR, you can disable re-enterable in
your ISR or check if the functions you are using are re-enterable.

Quote:
> Thanks, please send me email.

> Cheer

> Qian

Regards,
Xu Yifeng


Fri, 24 Jul 1998 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. C question : redefining a new malloc() calling standard malloc()

2. to malloc() or not to malloc(), that is the question

3. safe malloc wrapper

4. Safe malloc of array-of-arrays...

5. Safer malloc/free

6. To malloc (new) or not to malloc? When is the question.

7. Why OleDbCommand objects are not thread safe?

8. memcpy( NULL, NULL 0 ) - safe or not?

9. ATL Objects Are Not Thread-safe?

10. Is ATL's CComPtr not thread safe ?!!

11. NetWare is not SAFE!!

12. Apartment thread is not safe ?

 

 
Powered by phpBB® Forum Software