strdup of param name/nick/blurb
- From: Alex Larsson <alexl redhat com>
- To: <gtk-devel-list gnome org>
- Subject: strdup of param name/nick/blurb
- Date: Sat, 30 Jun 2001 21:09:02 -0400 (EDT)
I made a little patch that prints the amount of memory wasted on
strdup()ing the name, nick and blurb for paramspecs:
Index: gobject/gparam.c
===================================================================
RCS file: /cvs/gnome/glib/gobject/gparam.c,v
retrieving revision 1.16
diff -u -p -r1.16 gparam.c
--- gobject/gparam.c 2001/06/28 17:05:12 1.16
+++ gobject/gparam.c 2001/07/01 00:58:09
@@ -242,6 +242,10 @@ g_param_spec_internal (GType para
GParamFlags flags)
{
GParamSpec *pspec;
+ static int name_bloat=0;
+ static int nick_bloat=0;
+ static int blurb_bloat=0;
+
g_return_val_if_fail (G_TYPE_IS_PARAM (param_type) && param_type !=
G_TYPE_PARAM, NULL);
g_return_val_if_fail (name != NULL, NULL);
@@ -254,6 +258,15 @@ g_param_spec_internal (GType para
pspec->blurb = g_strdup (blurb);
pspec->flags = (flags & G_PARAM_USER_MASK) | (flags & G_PARAM_MASK);
+ if (pspec->name)
+ name_bloat += strlen (pspec->name) + 1;
+ if (pspec->nick)
+ nick_bloat += strlen (pspec->nick) + 1;
+ if (pspec->blurb)
+ blurb_bloat += strlen (pspec->blurb) + 1;
+ g_print ("bloat: name=%d nick=%d blurb=%d tot=%d\n",
+ name_bloat, nick_bloat, blurb_bloat,
+ name_bloat + nick_bloat + blurb_bloat);
return pspec;
}
Running the attached program which touches all types gives:
bloat: name=5150 nick=5714 blurb=17545 tot=28409
This tells us two things.
1) About 30k was wasted on duplicating the strings.
2) Our blurbs suck. At 424 params, we only have in average 41 chars per
blurb.
Running testgtk does not touch all the types, so there we get only:
bloat: name=2994 nick=3253 blurb=10961 tot=17208
/ Alex
#include <gtk/gtk.h>
volatile GType typ;
void
init_obj (GType type)
{
g_print ("type: %s\n", g_type_name (type));
typ = type;
g_type_class_ref (type);
}
void
init_boxed (GType type)
{
g_print ("type: %s\n", g_type_name (type));
typ = type;
}
void
init_iface (GType type)
{
g_print ("type: %s\n", g_type_name (type));
typ = type;
}
int
main(int argc, char *argv[])
{
gtk_init (&argc, &argv);
init_boxed (pango_color_get_type ());
init_boxed (pango_attr_list_get_type ());
init_obj (pango_context_get_type ());
init_obj (pango_font_get_type ());
init_obj (pango_font_map_get_type ());
init_obj (pango_layout_get_type ());
init_obj (pango_x_font_map_get_type ());
init_obj (pango_xft_font_get_type ());
init_obj (pango_ot_info_get_type ());
init_obj (pango_ot_ruleset_get_type ());
init_obj (pango_attr_type_get_type ());
init_obj (pango_underline_get_type ());
init_obj (pango_coverage_level_get_type ());
init_obj (pango_style_get_type ());
init_obj (pango_variant_get_type ());
init_obj (pango_weight_get_type ());
init_obj (pango_stretch_get_type ());
init_obj (pango_alignment_get_type ());
init_obj (pango_wrap_mode_get_type ());
init_obj (pango_tab_align_get_type ());
init_obj (pango_direction_get_type ());
init_obj (_gdk_pixmap_impl_get_type ());
init_obj (_gdk_window_impl_get_type ());
init_obj (gdk_axis_use_get_type ());
init_obj (gdk_byte_order_get_type ());
init_obj (gdk_cap_style_get_type ());
init_boxed (gdk_color_get_type ());
init_obj (gdk_colormap_get_type ());
init_obj (gdk_crossing_mode_get_type ());
init_boxed (gdk_cursor_get_type ());
init_obj (gdk_cursor_type_get_type ());
init_obj (gdk_device_get_type ());
init_obj (gdk_drag_action_get_type ());
init_obj (gdk_drag_context_get_type ());
init_obj (gdk_drag_protocol_get_type ());
init_obj (gdk_drawable_get_type ());
init_obj (gdk_drawable_impl_x11_get_type ());
init_boxed (gdk_event_get_type ());
init_obj (gdk_event_mask_get_type ());
init_obj (gdk_event_type_get_type ());
init_obj (gdk_extension_mode_get_type ());
init_obj (gdk_fill_get_type ());
init_obj (gdk_fill_rule_get_type ());
init_obj (gdk_filter_return_get_type ());
init_boxed (gdk_font_get_type ());
init_obj (gdk_font_type_get_type ());
init_obj (gdk_function_get_type ());
init_obj (gdk_gc_get_type ());
init_obj (gdk_gc_values_mask_get_type ());
init_obj (gdk_gc_x11_get_type ());
init_obj (gdk_grab_status_get_type ());
init_obj (gdk_gravity_get_type ());
init_obj (gdk_image_get_type ());
init_obj (gdk_image_type_get_type ());
init_obj (gdk_input_condition_get_type ());
init_obj (gdk_input_mode_get_type ());
init_obj (gdk_input_source_get_type ());
init_obj (gdk_join_style_get_type ());
init_obj (gdk_keymap_get_type ());
init_obj (gdk_line_style_get_type ());
init_obj (gdk_modifier_type_get_type ());
init_obj (gdk_notify_type_get_type ());
init_obj (gdk_overlap_type_get_type ());
init_obj (gdk_pixbuf_animation_get_type ());
init_obj (gdk_pixbuf_animation_iter_get_type ());
init_obj (gdk_pixbuf_get_type ());
// gdk_pixbuf_gif_anim_get_type ();
// gdk_pixbuf_gif_anim_iter_get_type ();
init_obj (gdk_pixbuf_loader_get_type ());
init_obj (gdk_pixmap_get_type ());
init_obj (gdk_pixmap_impl_x11_get_type ());
init_obj (gdk_prop_mode_get_type ());
init_obj (gdk_property_state_get_type ());
init_boxed (gdk_rectangle_get_type ());
init_obj (gdk_rgb_dither_get_type ());
init_obj (gdk_scroll_direction_get_type ());
init_obj (gdk_selection_get_type ());
init_obj (gdk_selection_type_get_type ());
init_obj (gdk_setting_action_get_type ());
init_obj (gdk_status_get_type ());
init_obj (gdk_subwindow_mode_get_type ());
init_obj (gdk_target_get_type ());
init_obj (gdk_visibility_state_get_type ());
init_obj (gdk_visual_get_type ());
init_obj (gdk_visual_type_get_type ());
init_obj (gdk_window_attributes_type_get_type ());
init_obj (gdk_window_class_get_type ());
init_obj (gdk_window_edge_get_type ());
init_obj (gdk_window_hints_get_type ());
init_obj (gdk_window_impl_x11_get_type ());
init_obj (gdk_window_object_get_type ());
init_obj (gdk_window_state_get_type ());
init_obj (gdk_window_type_get_type ());
init_obj (gdk_window_type_hint_get_type ());
init_obj (gdk_wm_decoration_get_type ());
init_obj (gdk_wm_function_get_type ());
init_obj (gtk_settings_get_type ());
init_obj (gtk_accel_label_get_type ());
init_obj (gtk_accessible_get_type ());
init_obj (gtk_adjustment_get_type ());
init_obj (gtk_alignment_get_type ());
init_obj (gtk_arrow_get_type ());
init_obj (gtk_aspect_frame_get_type ());
init_obj (gtk_bin_get_type ());
init_obj (gtk_box_get_type ());
init_obj (gtk_button_box_get_type ());
init_obj (gtk_button_get_type ());
init_obj (gtk_calendar_get_type ());
init_obj (gtk_cell_renderer_get_type ());
init_obj (gtk_cell_renderer_pixbuf_get_type ());
init_obj (gtk_cell_renderer_text_get_type ());
init_obj (gtk_cell_renderer_text_pixbuf_get_type ());
init_obj (gtk_cell_renderer_toggle_get_type ());
init_obj (gtk_check_button_get_type ());
init_obj (gtk_check_menu_item_get_type ());
init_obj (gtk_clist_get_type ());
init_obj (gtk_color_selection_dialog_get_type ());
init_obj (gtk_combo_get_type ());
init_obj (gtk_container_get_type ());
init_obj (gtk_ctree_get_type ());
init_obj (gtk_curve_get_type ());
init_obj (gtk_dialog_get_type ());
init_obj (gtk_drawing_area_get_type ());
init_obj (gtk_entry_get_type ());
init_obj (gtk_event_box_get_type ());
init_obj (gtk_file_selection_get_type ());
init_obj (gtk_fixed_get_type ());
init_obj (gtk_font_selection_dialog_get_type ());
init_obj (gtk_font_selection_get_type ());
init_obj (gtk_frame_get_type ());
init_obj (gtk_gamma_curve_get_type ());
init_obj (gtk_handle_box_get_type ());
init_obj (gtk_hbox_get_type ());
init_obj (gtk_hbutton_box_get_type ());
init_obj (gtk_hpaned_get_type ());
init_obj (gtk_hruler_get_type ());
init_obj (gtk_hscale_get_type ());
init_obj (gtk_hscrollbar_get_type ());
init_obj (gtk_hseparator_get_type ());
init_obj (gtk_hsv_get_type ());
init_obj (gtk_icon_factory_get_type ());
init_obj (gtk_im_context_get_type ());
init_obj (gtk_im_context_simple_get_type ());
init_obj (gtk_im_multicontext_get_type ());
init_obj (gtk_image_get_type ());
init_obj (gtk_image_menu_item_get_type ());
init_obj (gtk_input_dialog_get_type ());
init_obj (gtk_invisible_get_type ());
init_obj (gtk_item_factory_get_type ());
init_obj (gtk_item_get_type ());
init_obj (gtk_label_get_type ());
init_obj (gtk_layout_get_type ());
init_obj (gtk_list_get_type ());
init_obj (gtk_list_item_get_type ());
init_obj (gtk_list_store_get_type ());
init_obj (gtk_message_dialog_get_type ());
init_obj (gtk_misc_get_type ());
init_obj (gtk_notebook_get_type ());
init_obj (gtk_object_get_type ());
init_obj (gtk_old_editable_get_type ());
init_obj (gtk_option_menu_get_type ());
// gtk_packer_get_type ();
init_obj (gtk_paned_get_type ());
init_obj (gtk_pixmap_get_type ());
init_obj (gtk_plug_get_type ());
init_obj (gtk_preview_get_type ());
init_obj (gtk_progress_bar_get_type ());
init_obj (gtk_progress_get_type ());
init_obj (gtk_radio_button_get_type ());
init_obj (gtk_radio_menu_item_get_type ());
init_obj (gtk_range_get_type ());
init_obj (gtk_rc_style_get_type ());
init_obj (gtk_ruler_get_type ());
init_obj (gtk_scale_get_type ());
init_obj (gtk_scrollbar_get_type ());
init_obj (gtk_scrolled_window_get_type ());
init_obj (gtk_separator_get_type ());
init_obj (gtk_separator_menu_item_get_type ());
init_obj (gtk_size_group_get_type ());
init_obj (gtk_socket_get_type ());
init_obj (gtk_spin_button_get_type ());
init_obj (gtk_statusbar_get_type ());
init_obj (gtk_style_get_type ());
init_obj (gtk_table_get_type ());
init_obj (gtk_tearoff_menu_item_get_type ());
init_obj (gtk_text_buffer_get_type ());
init_obj (gtk_text_child_anchor_get_type ());
init_obj (gtk_text_get_type ());
init_obj (gtk_text_layout_get_type ());
init_obj (gtk_text_mark_get_type ());
init_obj (gtk_text_tag_get_type ());
init_obj (gtk_text_tag_table_get_type ());
init_obj (gtk_text_view_get_type ());
init_obj (gtk_theme_engine_get_type ());
init_obj (gtk_tips_query_get_type ());
init_obj (gtk_toggle_button_get_type ());
init_obj (gtk_tooltips_get_type ());
init_obj (gtk_tree_get_type ());
init_obj (gtk_tree_item_get_type ());
init_obj (gtk_tree_model_sort_get_type ());
init_obj (gtk_tree_selection_get_type ());
init_obj (gtk_tree_store_get_type ());
init_obj (gtk_tree_view_column_get_type ());
init_obj (gtk_tree_view_get_type ());
init_obj (gtk_vbox_get_type ());
init_obj (gtk_vbutton_box_get_type ());
init_obj (gtk_viewport_get_type ());
init_obj (gtk_vpaned_get_type ());
init_obj (gtk_vruler_get_type ());
init_obj (gtk_vscale_get_type ());
init_obj (gtk_vscrollbar_get_type ());
init_obj (gtk_vseparator_get_type ());
init_obj (gtk_widget_get_type ());
init_obj (gtk_window_get_type ());
init_obj (gtk_window_group_get_type ());
init_iface (gtk_tree_sortable_get_type ());
init_iface (gtk_tree_model_get_type ());
init_iface (gtk_tree_drag_dest_get_type ());
init_iface (gtk_tree_drag_source_get_type ());
init_obj (gtk_toolbar_get_type ());
init_obj (gtk_menu_bar_get_type ());
init_obj (gtk_menu_item_get_type ());
init_iface (gtk_editable_get_type ());
init_obj (gtk_menu_get_type ());
init_obj (gtk_menu_shell_get_type ());
init_obj (gtk_color_selection_get_type ());
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]