×

Loading...

Topic

This topic has been archived. It cannot be replied.
  • 工作学习 / IT技术讨论 / 请问用C如何动态分配一个数组,其内存首地址由参数制定。我是象汇编那样用指针直接访问内存。有相关的函数可以调用么? malloc, calloc 好象不能指定地址。
    • 为什么要这样?这在保护模式下是很危险的。如果要共享数据,可以 使用共享内存的方式。
      • 是一个嵌入软件,软件方面在RAM指定地址分配一个数组,同硬件共享。我是用汇编写的,现在我想知道用C是否有相关的函数可以按指定地址分配数组。
        • 在95上可以直接写内存地址呀。直接用输出语句就行了。在31下困难些,要计算地址偏移,想来你也不需要写31下的程序。
    • I don't get you, it might be better if you describe it in English. I go nuts when people start to talk about programming in chinese terminologies.
      • sorry, next time i'll do it in english.
    • The answer is machine (CPU type) and operating system related
      The answer is machine (CPU type) and operating system related. For DOS (of course Intel CPU), you can directly assign the absolute address of the block of memory to the memory pointer. For a near pointer, just offset need to be assigned. For a far pointer, both offset and segment. However you should code to protect the block of memory allocated in this way.
      • Hi, so long no see. How r u? You r a really high hand.
        • Not so bad. I just have a little bit of obsolet skill which is useless here.
      • yes,this is what i'm doing... thanks!
    • Thanks guys, I just wonder whether there is a function i can call to do that. I must make sure before i told others that we can't do it with something like malloc, calloc... and the only way is using pointer.
      • You can not find a standard function nowaday, I think.