China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-08-01 04:37
中国DOS联盟论坛 » DOS开发编程 & 发展交流 (开发室) » How to free space occupied by a buffer in TC View 1,013 Replies 6
Original Poster Posted 2003-11-13 00:00 ·  中国 陕西 西安 电信
初级用户
★★
忍者
Credits 376
Posts 86
Joined 2003-10-16 00:00
22-year member
UID 11361
Gender Male
Status Offline
How do I free the space occupied by a buffer in TC so I can load more images? Please give me some pointers, experts!
以C语言软件开发为主:http://sunny1979.icpcn.com
Floor 2 Posted 2003-11-14 00:00 ·  中国 湖北 武汉 鹏博士宽带
中级用户
★★
Credits 286
Posts 59
Joined 2003-04-08 00:00
23-year member
UID 1437
Gender Male
Status Offline
I don't quite understand what you mean. If the space was allocated with functions like malloc or alloc, use the free function to release it. Then the space occupied by the buffer is gone, and the buffer can no longer be used, so you'd have to allocate it again. If you want to use the original buffer space, just use it directly—the new content will overwrite the old content.
Floor 3 Posted 2003-11-18 00:00 ·  中国 陕西 西安 电信
初级用户
★★
忍者
Credits 376
Posts 86
Joined 2003-10-16 00:00
22-year member
UID 11361
Gender Male
Status Offline
To the gentleman on the second reply: I did allocate the space with functions like malloc and alloc, but I can't use free to release the occupied space. If I try to use the original buffer space to display another image, it hangs. The original program is on my homepage: http://sunny1979.icpcn.com, under My Resources, image display program. Sorry to trouble you, please take a look and see what's going on! Thanks in advance!
以C语言软件开发为主:http://sunny1979.icpcn.com
Floor 4 Posted 2003-11-18 00:00 ·  中国 湖北 武汉 鹏博士宽带
中级用户
★★
Credits 286
Posts 59
Joined 2003-04-08 00:00
23-year member
UID 1437
Gender Male
Status Offline
There is no "image display program" under "My Resources" on your homepage, but there is a program called "TC loading 16-color BMP files" under "My Works". I don't know whether that's the one you mean. There were no errors during compilation, and I also got the hang you mentioned. I noticed there is a line like this near the end of the main function in your source code:
if((buffer=malloc(ff->ff_fsize))==NULL)exit(0);
I changed the malloc in it to farmalloc, and the problem seemed to be solved (I tried many times and it didn't hang). You can try changing it and see if it works. My guess is that malloc easily gets space from the DOS system area, causing the DOS system to crash, while farmalloc is more reliable.
Floor 5 Posted 2003-11-20 00:00 ·  中国 陕西 西安 电信
初级用户
★★
忍者
Credits 376
Posts 86
Joined 2003-10-16 00:00
22-year member
UID 11361
Gender Male
Status Offline
I changed the malloc in it to farmalloc, and it hung! If I don't change it, it can still run. Maybe the settings are different! It can only load this one image; if I load another one, it definitely hangs! Can you load another image too?
以C语言软件开发为主:http://sunny1979.icpcn.com
Floor 6 Posted 2003-11-20 00:00 ·  中国 湖北 武汉 鹏博士宽带
中级用户
★★
Credits 286
Posts 59
Joined 2003-04-08 00:00
23-year member
UID 1437
Gender Male
Status Offline
Try changing the compile mode to large or huge. I'm using huge


Floor 7 Posted 2003-11-20 00:00 ·  中国 陕西 西安 电信
初级用户
★★
忍者
Credits 376
Posts 86
Joined 2003-10-16 00:00
22-year member
UID 11361
Gender Male
Status Offline
Why can it only load one image?
以C语言软件开发为主:http://sunny1979.icpcn.com
Forum Jump: