With the explosive growth of data at the edge in the Industrial Internet of Things (IIoT), edge devices are increasingly performing more data processing tasks to alleviate the load on cloud servers. To achieve this goal, Programmable Logic Controllers (PLCs) are gradually transitioning into edge PLCs. However, efficiently executing a large number of computational tasks in memory-limited edge PLCs is a significant challenge. Therefore, there is a need to design an efficient memory allocation strategy for edge PLCs. This paper proposes a dynamic memory allocation strategy for edge PLCs. It adopts an approach of organizing memory into small blocks to handle memory requests from real-time tasks and utilizes a well-performing dynamic programming method for resource allocation problems to handle memory requests from non-real-time tasks. This approach ensures real-time performance while improving the efficiency of non-real-time task processing. In the simulation experiments, the algorithm implemented based on this allocation strategy is compared with the default method and several open-source memory allocators. The experimental results demonstrate that the proposed algorithm, on average, improves the speed of real-time task processing by 13.7% and achieves a maximum speed improvement of 17.0% for non-real-time task processing. The experimental results show that the allocation strategy effectively improves memory allocation efficiency in memory-limited environments.