Project

General

Profile

Feature #10082

[PATCH] add ZALLOC* macros to reduce ALLOC + MEMZERO calls

Added by normalperson (Eric Wong) almost 3 years ago. Updated almost 3 years ago.

Status:
Closed
Priority:
Normal
Target version:
[ruby-core:63939]

Description

This reduces code and binary sizes.
ZALLOC macros are accessible via public API for exts

OK to add this API? It should simplify some code and reduce typos.

zalloc.patch View (7.4 KB) normalperson (Eric Wong), 07/22/2014 10:31 PM

History

#2 [ruby-core:63952] Updated by tad (Tadashi Saito) almost 3 years ago

The basic policy of patch feels great, but why don't you name CALLOC?

I feel CALLOC is more straitforward because calloc(3) is in the standard and
ZALLOC(_N) already uses calloc().

#3 [ruby-core:63953] Updated by normalperson (Eric Wong) almost 3 years ago

tad.a.digger@gmail.com wrote:

The basic policy of patch feels great, but why don't you name CALLOC?

I feel CALLOC is more straitforward because calloc(3) is in the standard and
ZALLOC(_N) already uses calloc().

I considered ZALLOC_N == CALLOC, but the arguments are reversed
for calloc(3), so I didn't want to risk that confusion, either.

I chose ZALLOC based on kzalloc/kmem_cache_zalloc in the Linux kernel.

On a related note: maybe RB_ZALLOC or RUBY_ZALLOC would be better, but
that would be inconsistent with existing ALLOC(N) and REALLOCN, too.

Naming is hard :<

matz/ko1 can make the final decision.

I'll commit in a day or so if we cannot decide, the name may still
change after commit.

#4 [ruby-core:63963] Updated by tad (Tadashi Saito) almost 3 years ago

I considered ZALLOC_N == CALLOC, but the arguments are reversed
for calloc(3), so I didn't want to risk that confusion, either.

I agree with your concern. ZALLOC may be better.

(My only concern is that zlib uses "zalloc" as its API, but we will
not have to worry about it:
https://github.com/ruby/ruby/blob/543b402/ext/zlib/zlib.c#L609 )

#5 [ruby-core:63975] Updated by nobu (Nobuyoshi Nakada) almost 3 years ago

Tadashi Saito wrote:

(My only concern is that zlib uses "zalloc" as its API, but we will
not have to worry about it:
https://github.com/ruby/ruby/blob/543b402/ext/zlib/zlib.c#L609 )

How about 0ALLOC()? ;)

#6 [ruby-core:64040] Updated by normalperson (Eric Wong) almost 3 years ago

  • Status changed from Open to Closed
  • Assignee changed from ko1 (Koichi Sasada) to normalperson (Eric Wong)

Also available in: Atom PDF