# Pointer to c array in Ruby

**URL:** <https://www.ruby-forum.com/t/pointer-to-c-array-in-ruby/77884>\
**Category:** Ruby\
**Created:** [March 7, 2006, 4:44pm UTC](https://www.ruby-forum.com/t/pointer-to-c-array-in-ruby/77884 "2006-03-07T16:44:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [March 7, 2006, 4:44pm UTC](https://www.ruby-forum.com/t/pointer-to-c-array-in-ruby/77884/1 "2006-03-07T16:44:55Z")

</div>

Beginner’s question: I’m creating a large C array using ALLOC\_N and I  
want to pass that pointer to different C extensions. I don’t want to  
create a Ruby array (i.e. using rb\_ary\_new4()) because I won’t operate  
on that array with any pure Ruby methods and I don’t want the memcpy  
overhead. How can I assign a variable to that pointer in Ruby and how  
do I prevent any garbage collection of my array?

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [March 8, 2006, 12:30pm UTC](https://www.ruby-forum.com/t/pointer-to-c-array-in-ruby/77884/2 "2006-03-08T12:30:36Z")

</div>

[http://www.whytheluckystiff.net/ruby/pickaxe/html/ext\_ruby.html](http://www.whytheluckystiff.net/ruby/pickaxe/html/ext_ruby.html)

This explains how to use Data\_Wrap\_Struct and how to manage garbage  
collection. The issue is not so much preventing garbage collection as  
making it possible.
